View Javadoc
1   /**
2    * This file Copyright (c) 2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.ui.dialog;
35  
36  import info.magnolia.ui.api.overlay.OverlayLayer;
37  import info.magnolia.ui.api.view.View;
38  import info.magnolia.ui.dialog.actionarea.view.EditorActionAreaView;
39  
40  import java.util.LinkedHashSet;
41  import java.util.Set;
42  
43  import com.vaadin.event.ShortcutListener;
44  import com.vaadin.ui.AbstractComponent;
45  import com.vaadin.ui.CustomComponent;
46  
47  /**
48   *.
49   */
50  public class ResurfaceDialogViewImpl extends CustomComponent implements DialogView {
51  
52      private String title;
53      private boolean isClosable;
54      private Set<DialogCloseHandler> dialogCloseHandlers = new LinkedHashSet<>();
55      private Set<ShortcutListener> shortcutListeners = new LinkedHashSet<>();
56      private EditorActionAreaView actionView;
57      private View contentView;
58      private DialogComponent dialogComponent;
59      private boolean isClosed = false;
60      private OverlayLayer.ModalityLevel modalityLevel;
61  
62      public ResurfaceDialogViewImpl() {
63          this.dialogComponent = new DialogComponent();
64      }
65  
66      public void setCaption(String caption) {
67          this.title = caption;
68      }
69  
70      @Override
71      public String getTitle() {
72          return title;
73      }
74  
75      @Override
76      public void setContent(View content) {
77          this.contentView = content;
78          this.dialogComponent.setContent(content.asVaadinComponent());
79      }
80  
81      @Override
82      public void setClosable(boolean isClosable) {
83          this.isClosable = isClosable;
84      }
85  
86      @Override
87      public boolean isClosable() {
88          return this.isClosable;
89      }
90  
91      @Override
92      public void close() {
93          // Some handler could call #close() method once again, but the handlers should be called only once -
94          // all the subsequent calls should be avoided.
95          if (!isClosed) {
96              isClosed = true;
97              this.dialogCloseHandlers.forEach(handler -> handler.onDialogClose(this));
98          }
99      }
100 
101     @Override
102     public void addDialogCloseHandler(DialogCloseHandler handler) {
103         dialogCloseHandlers.add(handler);
104     }
105 
106     @Override
107     public void removeDialogCloseHandler(DialogCloseHandler handler) {
108         dialogCloseHandlers.remove(handler);
109     }
110 
111     @Override
112     public void addShortcut(ShortcutListener shortcut) {
113         this.shortcutListeners.add(shortcut);
114         this.dialogComponent.addShortcutListener(shortcut);
115     }
116 
117     @Override
118     public void removeShortcut(ShortcutListener shortcut) {
119         this.shortcutListeners.remove(shortcut);
120         this.dialogComponent.removeShortcutListener(shortcut);
121     }
122 
123     @Override
124     public void setActionAreaView(EditorActionAreaView actionView) {
125         this.actionView = actionView;
126         this.dialogComponent.setFooter(actionView.asVaadinComponent());
127     }
128 
129     @Override
130     public View getContentView() {
131         return this.contentView;
132     }
133 
134     @Override
135     public EditorActionAreaView getActionAreaView() {
136         return this.actionView;
137     }
138 
139     @Override
140     public OverlayLayer.ModalityLevel getModalityLevel() {
141         return modalityLevel;
142     }
143 
144     @Override
145     public AbstractComponent asVaadinComponent() {
146         return this.dialogComponent;
147     }
148 
149     @Override
150     public void setModalityLevel(OverlayLayer.ModalityLevel modalityLevel) {
151         this.modalityLevel = modalityLevel;
152     }
153 
154     @Override
155     public void setDescriptionVisible(boolean isDescriptionVisible) {
156         // NOOP
157     }
158 
159     @Override
160     public void setDescription(String description) {
161         // NOOP
162     }
163 }