001 /* 
002  * Copyright 2008-2017 the original author or authors. 
003  * 
004  * Licensed under the Apache License, Version 2.0 (the "License"); 
005  * you may not use this file except in compliance with the License. 
006  * You may obtain a copy of the License at 
007  * 
008  *     http://www.apache.org/licenses/LICENSE-2.0 
009  * 
010  * Unless required by applicable law or agreed to in writing, software 
011  * distributed under the License is distributed on an "AS IS" BASIS, 
012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
013  * See the License for the specific language governing permissions and 
014  * limitations under the License. 
015  */ 
016 package griffon.core.view; 
017  
018 import griffon.core.GriffonApplication; 
019 import griffon.core.ShutdownHandler; 
020  
021 import javax.annotation.Nonnull; 
022 import javax.annotation.Nullable; 
023 import java.util.Collection; 
024 import java.util.Set; 
025  
026 /** 
027  * Controls a set of windows that belong to the application.<p> 
028  * Windows that are controlled by a WindowManager can be shown/hidden 
029  * using a custom strategy ({@code WindowDisplayHandler}) 
030  * 
031  * @author Andres Almiray 
032  * @since 2.0.0 
033  */ 
034 public interface WindowManager<W> extends ShutdownHandler { 
035     /** 
036      * Finds a Window by name. 
037      * 
038      * @param name the value of the of the Window's name 
039      * @return a Window if a match is found, null otherwise. 
040      */ 
041     @Nullable 
042     W findWindow(@Nonnull String name); 
043  
044     /** 
045      * Convenience method to get a managed Window by index.<p> 
046      * Follows the Groovy conventions for overriding the [] operator. 
047      * 
048      * @param index the index of the Window to be retrieved 
049      * @return the Window found at the specified index 
050      * @throws ArrayIndexOutOfBoundsException if the index is invalid (below 0 or greater than the size 
051      *                                        of the managed windows list) 
052      */ 
053     @Nullable 
054     W getAt(int index); 
055  
056     /** 
057      * Finds the Window that should be displayed during the Ready phase of an application.<p> 
058      * The WindowManager expects a configuration flag <code>windowManager.startingWindow</code> to be 
059      * present in order to determine which Window will be displayed during the Ready phase. If no configuration 
060      * is found the WindowManager will pick the first Window found in the list of managed windows.<p> 
061      * The configuration flag accepts two value types:<ul> 
062      * <li>a String that defines the name of the Window. You must make sure the Window has a matching name property.</li> 
063      * <li>a Number that defines the index of the Window in the list of managed windows.</li> 
064      * </ul> 
065      * 
066      * @return a Window that matches the given criteria or null if no match is found. 
067      */ 
068     @Nullable 
069     W getStartingWindow(); 
070  
071     /** 
072      * Returns the collection of windows managed by this manager. 
073      * 
074      * @return a Collection of currently managed windows 
075      */ 
076     @Nonnull 
077     Collection<W> getWindows(); 
078  
079     /** 
080      * Returns a set of names related to all windows managed by this manager. 
081      * 
082      * @return a Set of managed window names 
083      * @since 2.3.0 
084      */ 
085     @Nonnull 
086     Set<String> getWindowNames(); 
087  
088     /** 
089      * Lookups a name related to a Window. 
090      * 
091      * @param window the window to be looked up 
092      * @return the name of the window if it's managed by this manager, <tt>null</tt> otherwise. 
093      * @since 2.3.0 
094      */ 
095     @Nullable 
096     String findWindowName(@Nonnull W window); 
097  
098     /** 
099      * Lookups the index related to a Window. 
100      * 
101      * @param window the window to be looked up 
102      * @return the index of the window if it's managed by this manager, <tt>-1</tt> otherwise. 
103      * @since 2.3.0 
104      */ 
105     int indexOf(@Nonnull W window); 
106  
107     /** 
108      * Registers a window on this manager if an only if the window is not null 
109      * and it's not registered already. 
110      * 
111      * @param name   the value of the of the Window's name 
112      * @param window the window to be added to the list of managed windows 
113      */ 
114     void attach(@Nonnull String name, @Nonnull W window); 
115  
116     /** 
117      * Removes the window from the list of manages windows if and only if it 
118      * is registered with this manager. 
119      * 
120      * @param name the value of the of the Window's name 
121      */ 
122     void detach(@Nonnull String name); 
123  
124     /** 
125      * Shows the window.<p> 
126      * This method is executed <b>SYNCHRONOUSLY</b> in the UI thread. 
127      * 
128      * @param window the window to show 
129      */ 
130     void show(@Nonnull W window); 
131  
132     /** 
133      * Shows the window.<p> 
134      * This method is executed <b>SYNCHRONOUSLY</b> in the UI thread. 
135      * 
136      * @param name the name of window to show 
137      */ 
138     void show(@Nonnull String name); 
139  
140     /** 
141      * Hides the window.<p> 
142      * This method is executed <b>SYNCHRONOUSLY</b> in the UI thread. 
143      * 
144      * @param window the window to hide 
145      */ 
146     void hide(@Nonnull W window); 
147  
148     /** 
149      * Hides the window.<p> 
150      * This method is executed <b>SYNCHRONOUSLY</b> in the UI thread. 
151      * 
152      * @param name the name of window to hide 
153      */ 
154     void hide(@Nonnull String name); 
155  
156     boolean canShutdown(@Nonnull GriffonApplication app); 
157  
158     /** 
159      * Hides all visible windows 
160      */ 
161     void onShutdown(@Nonnull GriffonApplication app); 
162  
163     /** 
164      * Counts how many Windows are visible regardless of their attached status to this WindowManager. 
165      * 
166      * @return the number of visible Windows 
167      */ 
168     int countVisibleWindows(); 
169  
170     /** 
171      * Returns the value of the "application.autoShutdown" configuration flag. 
172      * 
173      * @return the value of the "application.autoShutdown" configuration flag. 
174      */ 
175     boolean isAutoShutdown(); 
176 }
    
    |