KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > app > ApplicationInstance


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2004 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.app;
31
32 import java.beans.PropertyChangeListener JavaDoc;
33 import java.beans.PropertyChangeSupport JavaDoc;
34 import java.io.Serializable JavaDoc;
35 import java.lang.ref.WeakReference JavaDoc;
36 import java.util.ArrayList JavaDoc;
37 import java.util.HashMap JavaDoc;
38 import java.util.Iterator JavaDoc;
39 import java.util.List JavaDoc;
40 import java.util.Locale JavaDoc;
41 import java.util.Map JavaDoc;
42
43 import nextapp.echo2.app.update.ServerUpdateManager;
44 import nextapp.echo2.app.update.UpdateManager;
45 import nextapp.echo2.app.util.Uid;
46
47 /**
48  * A single user-instance of an Echo application.
49  */

50 public abstract class ApplicationInstance
51 implements Serializable JavaDoc {
52     
53     /** The name and version of the Echo API in use. */
54     public static final String JavaDoc ID_STRING = "NextApp Echo v2.1.0.rc2";
55
56     public static final String JavaDoc FOCUSED_COMPONENT_CHANGED_PROPERTY = "focusedComponent";
57     public static final String JavaDoc LOCALE_CHANGED_PROPERTY = "locale";
58     public static final String JavaDoc MODAL_COMPONENTS_CHANGED_PROPERTY = "modalComponents";
59     public static final String JavaDoc WINDOWS_CHANGED_PROPERTY = "windows";
60     
61     /**
62      * A <code>ThreadLocal</code> reference to the
63      * <code>ApplicationInstance</code> relevant to the current thread.
64      */

65     private static final ThreadLocal JavaDoc activeInstance = new InheritableThreadLocal JavaDoc();
66     
67     /**
68      * Generates a system-level identifier (an identifier which is unique to all
69      * <code>ApplicationInstance</code>s).
70      *
71      * @return the generated identifier
72      * @see #generateId()
73      */

74     public static final String JavaDoc generateSystemId() {
75         return Uid.generateUidString();
76     }
77     
78     /**
79      * Returns a reference to the <code>ApplicationInstance</code> that is
80      * relevant to the current thread, or null if no instance is relevant.
81      *
82      * @return the relevant <code>ApplicationInstance</code>
83      */

84     public static final ApplicationInstance getActive() {
85         return (ApplicationInstance) activeInstance.get();
86     }
87
88     /**
89      * Sets the <code>ApplicationInstance</code> that is relevant to the
90      * current thread. This method should be invoked with a null
91      * argument when the previously set <code>ApplicationInstance</code> is
92      * no longer relevant.
93      * <p>
94      * <b>This method should only be invoked by the application container.</b>
95      *
96      * @param applicationInstance the relevant <code>ApplicationInstance</code>
97      */

98     public static final void setActive(ApplicationInstance applicationInstance) {
99         activeInstance.set(applicationInstance);
100     }
101
102     /**
103      * The presently focused component.
104      */

105     private transient WeakReference JavaDoc focusedComponent;
106
107     /**
108      * The default <code>Locale</code> of the application.
109      * This <code>Locale</code> will be inherited by <code>Component</code>s.
110      */

111     private Locale JavaDoc locale;
112     
113     /**
114      * The default <code>LayoutDirection</code> of the application, derived
115      * from the application's <code>Locale</code>.
116      * This <code>LayoutDirection</code> will be inherited by
117      * <code>Component</code>s.
118      */

119     private LayoutDirection layoutDirection;
120
121     /**
122      * Contextual data.
123      * @see #getContextProperty(java.lang.String)
124      */

125     private Map JavaDoc context;
126     
127     /**
128      * Mapping from the render ids of all registered components to the
129      * <code>Component</code> instances themselves.
130      */

131     private Map JavaDoc renderIdToComponentMap;
132     
133     /**
134      * Mapping between <code>TaskQueueHandle</code>s and <code>List</code>s
135      * of <code>Runnable</code> tasks. Values may be null if a particular
136      * <code>TaskQueue</code> does not contain any tasks.
137      */

138     private HashMap JavaDoc taskQueueMap;
139     
140     /**
141      * Fires property change events for the instance object.
142      */

143     private PropertyChangeSupport JavaDoc propertyChangeSupport;
144
145     /**
146      * The <code>UpdateManager</code> handling updates to/from this application.
147      */

148     private UpdateManager updateManager;
149     
150     /**
151      * The top-level <code>Window</code>.
152      * Currently only one top-level is supported per
153      * <code>ApplicationInstance</code>.
154      */

155     private Window defaultWindow;
156     
157     /**
158      * The <code>StyleSheet</code> used by the application.
159      */

160     private StyleSheet styleSheet;
161
162     /**
163      * Collection of modal components, the last index representing the current
164      * modal context.
165      */

166     private List JavaDoc modalComponents;
167     
168     /**
169      * The next available sequentially generated
170      * <code>ApplicationInstance</code>-unique identifier value.
171      * @see #generateId()
172      */

173     private long nextId;
174     
175     /**
176      * Creates an <code>ApplicationInstance</code>.
177      */

178     public ApplicationInstance() {
179         super();
180         
181         locale = Locale.getDefault();
182         layoutDirection = LayoutDirection.forLocale(locale);
183         
184         propertyChangeSupport = new PropertyChangeSupport JavaDoc(this);
185         updateManager = new UpdateManager(this);
186         renderIdToComponentMap = new HashMap JavaDoc();
187         taskQueueMap = new HashMap JavaDoc();
188     }
189     
190     /**
191      * Adds a <code>PropertyChangeListener</code> to receive notification of
192      * application-level property changes.
193      *
194      * @param l the listener to add
195      */

196     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
197         propertyChangeSupport.addPropertyChangeListener(l);
198     }
199     
200     /**
201      * Creates a new task queue. A handle object representing the created task
202      * queue is returned. The created task queue will remain active until it is
203      * provided to the <code>removeTaskQueue()</code> method. Developers must
204      * take care to invoke <code>removeTaskQueue()</code> on any created
205      * task queues.
206      *
207      * @return a <code>TaskQueueHandler</code> representing the created task
208      * queue
209      * @see #removeTaskQueue(TaskQueueHandle)
210      */

211     public TaskQueueHandle createTaskQueue() {
212         TaskQueueHandle taskQueue = new TaskQueueHandle() { };
213         synchronized (taskQueueMap) {
214             taskQueueMap.put(taskQueue, null);
215         }
216         return taskQueue;
217     }
218     
219     /**
220      * Initializes the <code>ApplicationInstance</code>. This method is
221      * invoked by the application container.
222      *
223      * @return the default <code>Window</code> of the application
224      * @throws IllegalStateException in the event that the current thread is not
225      * permitted to update the state of the user interface
226      */

227     public final Window doInit() {
228         if (this != activeInstance.get()) {
229             throw new IllegalStateException JavaDoc(
230                     "Attempt to update state of application user interface outside of user interface thread.");
231         }
232         Window window = init();
233         setDefaultWindow(window);
234         doValidation();
235         return window;
236     }
237     
238     /**
239      * Validates all components registered with the application.
240      */

241     public final void doValidation() {
242         doValidation(defaultWindow);
243     }
244     
245     /**
246      * Validates a single component and then recursively validates its
247      * children. This is the recursive support method for
248      * the parameterless <code>doValidation()</code> method.
249      *
250      * @param c The component to be validated.
251      * @see #doValidation()
252      */

253     private void doValidation(Component c) {
254         c.validate();
255         int size = c.getComponentCount();
256         for (int index = 0; index < size; ++index) {
257             doValidation(c.getComponent(index));
258         }
259     }
260
261     /**
262      * Queues the given stateless <code>Command</code> for execution on the
263      * current client/server synchronization.
264      *
265      * @param command the <code>Command</code> to execute
266      */

267     public void enqueueCommand(Command command) {
268         updateManager.getServerUpdateManager().enqueueCommand(command);
269     }
270     
271     /**
272      * Enqueues a task to be run during the next client/server
273      * synchronization. The task will be run
274      * <b>synchronously</b> in the user interface update thread.
275      * Enqueuing a task in response to an external event will result
276      * in changes being pushed to the client.
277      *
278      * @param taskQueue the <code>TaskQueueHandle</code> representing the
279      * queue into which this task should be placed
280      * @param task the task to run on client/server synchronization
281      */

282     public void enqueueTask(TaskQueueHandle taskQueue, Runnable JavaDoc task) {
283         synchronized (taskQueueMap) {
284             List JavaDoc taskList = (List JavaDoc) taskQueueMap.get(taskQueue);
285             if (taskList == null) {
286                 taskList = new ArrayList JavaDoc();
287                 taskQueueMap.put(taskQueue, taskList);
288             }
289             taskList.add(task);
290         }
291     }
292     
293     /**
294      * Reports a bound property change.
295      *
296      * @param propertyName the name of the changed property
297      * @param oldValue the previous value of the property
298      * @param newValue the present value of the property
299      */

300     protected void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
301         propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
302     }
303     
304     /**
305      * Generates an identifier which is unique within this
306      * <code>ApplicationInstance</code>. This identifier should not be
307      * used outside of the context of this <code>ApplicationInstance</code>.
308      *
309      * @return the unique identifier
310      * @see #generateSystemId()
311      */

312     public String JavaDoc generateId() {
313         return Long.toString(nextId++);
314     }
315     
316     /**
317      * Returns the value of a contextual property.
318      * Contextual properties are typically set by an application
319      * container, e.g., the Web Container, in order to provide
320      * container-specific information. The property names of contextual
321      * properties are provided within the application container
322      * documentation when their use is required.
323      *
324      * @param propertyName the name of the object
325      * @return the object
326      */

327     public Object JavaDoc getContextProperty(String JavaDoc propertyName) {
328         return context == null ? null : context.get(propertyName);
329     }
330
331     /**
332      * Retrieves the component currently registered with the application
333      * with the specified render id.
334      *
335      * @param renderId the render id of the component
336      * @return the component (or null if no component with the specified
337      * render id is registered)
338      */

339     public Component getComponentByRenderId(String JavaDoc renderId) {
340         return (Component) renderIdToComponentMap.get(renderId);
341     }
342
343     /**
344      * Returns the default window of the application.
345      *
346      * @return the default <code>Window</code>
347      */

348     public Window getDefaultWindow() {
349         return defaultWindow;
350     }
351     
352     /**
353      * Returns the presently focused component, if known.
354      *
355      * @return the focused component
356      */

357     public Component getFocusedComponent() {
358         if (focusedComponent == null) {
359             return null;
360         } else {
361             return (Component) focusedComponent.get();
362         }
363     }
364     
365     /**
366      * Returns the application instance's default
367      * <code>LayoutDirection</code>.
368      *
369      * @return the <code>Locale</code>
370      */

371     public LayoutDirection getLayoutDirection() {
372         return layoutDirection;
373     }
374     
375     /**
376      * Returns the application instance's default <code>Locale</code>.
377      *
378      * @return the <code>Locale</code>
379      */

380     public Locale JavaDoc getLocale() {
381         return locale;
382     }
383     
384     /**
385      * Retrieves the root component of the current modal context, or null
386      * if no modal context exists. Components which are not within the
387      * descendant hierarchy of the modal context are barred from receiving
388      * user input.
389      *
390      * @return the root component of the modal context
391      */

392     public Component getModalContextRoot() {
393         if (modalComponents == null || modalComponents.size() == 0) {
394             return null;
395         } else {
396             for (int i = modalComponents.size() - 1; i >= 0; --i) {
397                 Component component = (Component) modalComponents.get(i);
398                 // Ignore invisible components.
399
if (component.isRenderVisible()) {
400                     return component;
401                 }
402             }
403             return null;
404         }
405     }
406     
407     /**
408      * Retrieves the style for the specified specified class of
409      * component / style name.
410      *
411      * @param componentClass the component <code>Class</code>
412      * @param styleName the component's specified style name
413      * @return the appropriate application-wide style, or null
414      * if none exists
415      */

416     public Style getStyle(Class JavaDoc componentClass, String JavaDoc styleName) {
417         if (styleSheet == null) {
418             return null;
419         } else {
420             return styleSheet.getStyle(componentClass, styleName);
421         }
422     }
423     
424     /**
425      * Retrieves the <code>UpdateManager</code> being used to manage the
426      * client/server synchronization of this <code>ApplicationInstance</code>
427      *
428      * @return the <code>UpdateManager</code>
429      */

430     public UpdateManager getUpdateManager() {
431         return updateManager;
432     }
433     
434     /**
435      * Determines if this <code>ApplicationInstance</code> currently has any
436      * active tasks queues, which might be monitoring external events.
437      *
438      * @return true if the instance has any task queues
439      */

440     public final boolean hasTaskQueues() {
441         return taskQueueMap.size() > 0;
442     }
443     
444     /**
445      * Determines if there are any queued tasks in any of the task
446      * queues associated with this <code>ApplicationInstance</code>.
447      * <p>
448      * This method may be overridden by an application in order to check
449      * on the status of long-running operations and enqueue tasks
450      * just-in-time. In such cases tasks should be <strong>enqueued</strong>
451      * and the value of <code>super.hasQueuedTasks()</code> should be
452      * returned. This method is not invoked by a user-interface thread and
453      * thus the component hierarchy may not be modified in
454      * overriding implementations.
455      *
456      * @return true if any tasks are queued
457      */

458     public boolean hasQueuedTasks() {
459         if (taskQueueMap.size() == 0) {
460             return false;
461         }
462         Iterator JavaDoc it = taskQueueMap.values().iterator();
463         while (it.hasNext()) {
464             List JavaDoc taskList = (List JavaDoc) it.next();
465             if (taskList != null && taskList.size() > 0) {
466                 return true;
467             }
468         }
469         return false;
470     }
471     
472     /**
473      * Determines if the given component is modal (i.e., that only components
474      * below it in the hierarchy should be enabled).
475      *
476      * @param component the <code>Component</code>
477      * @return true if the <code>Component</code> is modal
478      */

479     private boolean isModal(Component component) {
480         return modalComponents != null && modalComponents.contains(component);
481     }
482     
483     /**
484      * Invoked to initialize the application, returning the default window.
485      * The returned window must be visible.
486      *
487      * @return the default window of the application
488      */

489     public abstract Window init();
490     
491     /**
492      * Notifies the <code>UpdateManager</code> in response to a component
493      * property change or child addition/removal.
494      * <p>
495      * This method is invoked directly from <code>Component</code>s
496      * (rather than using a <code>PropertyChangeListener</code>) in the interest
497      * of memory efficiency.
498      *
499      * @param parent the parent/updated component
500      * @param propertyName the name of the property changed
501      * @param oldValue the previous value of the property
502      * (or the removed component in the case of a
503      * <code>CHILDREN_CHANGED_PROPERTY</code>)
504      * @param newValue the new value of the property
505      * (or the added component in the case of a
506      * <code>CHILDREN_CHANGED_PROPERTY</code>)
507      * @throws IllegalStateException in the event that the current thread is not
508      * permitted to update the state of the user interface
509      */

510     void notifyComponentPropertyChange(Component parent, String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
511         // Ensure current thread is a user interface thread.
512
if (this != activeInstance.get()) {
513             throw new IllegalStateException JavaDoc(
514                     "Attempt to update state of application user interface outside of user interface thread.");
515         }
516
517         ServerUpdateManager serverUpdateManager = updateManager.getServerUpdateManager();
518         if (Component.CHILDREN_CHANGED_PROPERTY.equals(propertyName)) {
519             if (newValue == null) {
520                 serverUpdateManager.processComponentRemove(parent, (Component) oldValue);
521             } else {
522                 serverUpdateManager.processComponentAdd(parent, (Component) newValue);
523             }
524         } else if (Component.PROPERTY_LAYOUT_DATA.equals(propertyName)) {
525             serverUpdateManager.processComponentLayoutDataUpdate(parent);
526         } else if (Component.VISIBLE_CHANGED_PROPERTY.equals(propertyName)) {
527             if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
528                 return;
529             }
530             serverUpdateManager.processComponentVisibilityUpdate(parent);
531         } else {
532             if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
533                 return;
534             }
535             if (parent instanceof ModalSupport && ModalSupport.MODAL_CHANGED_PROPERTY.equals(propertyName)) {
536                 setModal(parent, ((Boolean JavaDoc) newValue).booleanValue());
537             }
538             serverUpdateManager.processComponentPropertyUpdate(parent, propertyName, oldValue, newValue);
539         }
540     }
541     
542     /**
543      * Processes client input specific to the <code>ApplicationInstance</code>
544      * received from the <code>UpdateManager</code>.
545      * Derivative implementations should take care to invoke
546      * <code>super.processInput()</code>.
547      */

548     public void processInput(String JavaDoc propertyName, Object JavaDoc propertyValue) {
549         if (FOCUSED_COMPONENT_CHANGED_PROPERTY.equals(propertyName)) {
550             setFocusedComponent((Component) propertyValue);
551         }
552     }
553
554     /**
555      * Processes all queued tasks. This method may only be invoked from within a
556      * UI thread by the <code>UpdateManager</code>. Tasks are removed from queues
557      * once they have been processed.
558      */

559     public void processQueuedTasks() {
560         if (taskQueueMap.size() == 0) {
561             return;
562         }
563         
564         List JavaDoc currentTasks = new ArrayList JavaDoc();
565         synchronized (taskQueueMap) {
566             Iterator JavaDoc taskListsIt = taskQueueMap.values().iterator();
567             while (taskListsIt.hasNext()) {
568                 List JavaDoc tasks = (List JavaDoc) taskListsIt.next();
569                 if (tasks != null) {
570                     currentTasks.addAll(tasks);
571                     tasks.clear();
572                 }
573             }
574         }
575         Iterator JavaDoc it = currentTasks.iterator();
576         while (it.hasNext()) {
577             ((Runnable JavaDoc) it.next()).run();
578         }
579     }
580     
581     /**
582      * Registers a component with the <code>ApplicationInstance</code>.
583      * The component will be assigned a unique render id in the event that
584      * it does not currently have one.
585      * <p>
586      * This method is invoked by <code>Component.setApplicationInstance()</code>
587      *
588      * @param component the component to register
589      * @see Component#register(ApplicationInstance)
590      */

591     void registerComponent(Component component) {
592         String JavaDoc renderId = component.getRenderId();
593         if (renderId == null || renderIdToComponentMap.containsKey(renderId)) {
594             // Note that the render id is reassigned if it currently exists renderIdToComponentMap. This could be the case
595
// in the event a Component was being used in a pool.
596
component.assignRenderId(generateId());
597         }
598         renderIdToComponentMap.put(component.getRenderId(), component);
599         if (component instanceof ModalSupport && ((ModalSupport) component).isModal()) {
600             setModal(component, true);
601         }
602     }
603     
604     /**
605      * Removes a <code>PropertyChangeListener</code> from receiving
606      * notification of application-level property changes.
607      *
608      * @param l the listener to remove
609      */

610     public void removePropertyChangeListener(PropertyChangeListener JavaDoc l) {
611         propertyChangeSupport.removePropertyChangeListener(l);
612     }
613     
614     /**
615      * Removes the task queue described the specified
616      * <code>TaskQueueHandle</code>.
617      *
618      * @param taskQueueHandle the <code>TaskQueueHandle</code> specifying the
619      * task queue to remove
620      * @see #createTaskQueue()
621      */

622     public void removeTaskQueue(TaskQueueHandle taskQueueHandle) {
623         synchronized(taskQueueMap) {
624             taskQueueMap.remove(taskQueueHandle);
625         }
626     }
627     
628     /**
629      * Sets a contextual property.
630      *
631      * @param propertyName the property name
632      * @param propertyValue the property value
633      *
634      * @see #getContextProperty(java.lang.String)
635      */

636     public void setContextProperty(String JavaDoc propertyName, Object JavaDoc propertyValue) {
637         if (context == null) {
638             context = new HashMap JavaDoc();
639         }
640         if (propertyValue == null) {
641             context.remove(propertyName);
642         } else {
643             context.put(propertyName, propertyValue);
644         }
645     }
646     
647     /**
648      * Sets the default top-level window.
649      *
650      * @param window the default top-level window
651      */

652     private void setDefaultWindow(Window window) {
653         if (defaultWindow != null) {
654             throw new UnsupportedOperationException JavaDoc("Default window already set.");
655         }
656
657         defaultWindow = window;
658         window.register(this);
659         firePropertyChange(WINDOWS_CHANGED_PROPERTY, null, window);
660         window.doInit();
661     }
662     
663     /**
664      * Sets the presently focused component.
665      *
666      * @param newValue the component to be focused
667      */

668     public void setFocusedComponent(Component newValue) {
669         if (newValue instanceof DelegateFocusSupport) {
670             newValue = ((DelegateFocusSupport) newValue).getFocusComponent();
671         }
672         
673         Component oldValue = getFocusedComponent();
674         if (newValue == null) {
675             focusedComponent = null;
676         } else {
677             focusedComponent = new WeakReference JavaDoc(newValue);
678         }
679         propertyChangeSupport.firePropertyChange(FOCUSED_COMPONENT_CHANGED_PROPERTY, oldValue, newValue);
680         updateManager.getServerUpdateManager().processApplicationPropertyUpdate(FOCUSED_COMPONENT_CHANGED_PROPERTY,
681                 oldValue, newValue);
682     }
683     
684     /**
685      * Sets the default locale of the application.
686      *
687      * @param newValue the new locale
688      */

689     public void setLocale(Locale JavaDoc newValue) {
690         if (newValue == null) {
691             throw new IllegalArgumentException JavaDoc("ApplicationInstance Locale may not be null.");
692         }
693         Locale JavaDoc oldValue = locale;
694         locale = newValue;
695         layoutDirection = LayoutDirection.forLocale(locale);
696         propertyChangeSupport.firePropertyChange(LOCALE_CHANGED_PROPERTY, oldValue, newValue);
697         updateManager.getServerUpdateManager().processFullRefresh();
698     }
699     
700     /**
701      * Sets the modal state of a component (i.e, whether only it and
702      * components below it in the hierarchy should be enabled).
703      *
704      * @param component the <code>Component</code>
705      * @param newValue the new modal state
706      */

707     private void setModal(Component component, boolean newValue) {
708         boolean oldValue = isModal(component);
709         if (newValue) {
710             if (modalComponents == null) {
711                 modalComponents = new ArrayList JavaDoc();
712             }
713             if (!modalComponents.contains(component)) {
714                 modalComponents.add(component);
715             }
716         } else {
717             if (modalComponents != null) {
718                 modalComponents.remove(component);
719             }
720         }
721         firePropertyChange(MODAL_COMPONENTS_CHANGED_PROPERTY, new Boolean JavaDoc(oldValue), new Boolean JavaDoc(newValue));
722     }
723
724     /**
725      * Sets the <code>StyleSheet</code> of this
726      * <code>ApplicationInstance</code>. <code>Component</code>s
727      * registered with this instance will retrieve
728      * properties from the <code>StyleSheet</code>
729      * when property values are not specified directly
730      * in a <code>Component</code> or in its specified <code>Style</code>.
731      * <p>
732      * Note that setting the style sheet should be
733      * done sparingly, given that doing so forces the entire
734      * client state to be updated. Generally style sheets should
735      * only be reconfigured at application initialization and/or when
736      * the user changes the visual theme of a theme-capable application.
737      *
738      * @param styleSheet the new style sheet
739      */

740     public void setStyleSheet(StyleSheet styleSheet) {
741         this.styleSheet = styleSheet;
742         updateManager.getServerUpdateManager().processFullRefresh();
743     }
744
745     /**
746      * Unregisters a component from the <code>ApplicationInstance</code>.
747      * <p>
748      * This method is invoked by <code>Component.setApplicationInstance()</code>.
749      *
750      * @param component the component to unregister
751      * @see Component#register(ApplicationInstance)
752      */

753     void unregisterComponent(Component component) {
754         renderIdToComponentMap.remove(component.getRenderId());
755         if (component instanceof ModalSupport && ((ModalSupport) component).isModal()) {
756             setModal(component, false);
757         }
758     }
759     
760     /**
761      * Verifies that a <code>Component</code> is within the modal context,
762      * i.e., that if a modal <code>Component</code> is present, that it either
763      * is or is a child of that <code>Component</code>.
764      *
765      * @param component the <code>Component</code> to evaluate
766      * @return true if the <code>Component</code> is within the current
767      * modal context
768      * @see Component#verifyInput(java.lang.String, java.lang.Object)
769      */

770     boolean verifyModalContext(Component component) {
771         Component modalContextRoot = getModalContextRoot();
772         return modalContextRoot == null || modalContextRoot.isAncestorOf(component);
773     }
774 }
775
Popular Tags