KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > navigator > SaveablesProvider


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  ******************************************************************************/

11
12 package org.eclipse.ui.navigator;
13
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.ui.ISaveablesLifecycleListener;
16 import org.eclipse.ui.Saveable;
17 import org.eclipse.ui.SaveablesLifecycleEvent;
18 import org.eclipse.ui.services.IDisposable;
19
20 /**
21  * Provides {@link Saveable} objects to the common navigator, and allows to map
22  * between elements in the tree and models.
23  * <p>
24  * This class is intended to be subclassed by clients.
25  * </p>
26  * Instances of subclasses will be returned from content extensions that
27  * implement {@link IAdaptable}.
28  *
29  * @since 3.2
30  *
31  */

32 public abstract class SaveablesProvider implements IDisposable {
33
34     private ISaveablesLifecycleListener listener;
35
36     /**
37      * Creates a new saveable model provider. May only be called by subclasses.
38      *
39      */

40     protected SaveablesProvider() {
41     }
42
43     /**
44      * Initializes this SaveablesProvider with the given listener, and calls the hook method doInit().
45      *
46      * @param listener
47      */

48     final public void init(ISaveablesLifecycleListener listener) {
49         this.listener = listener;
50         doInit();
51     }
52
53     /**
54      * May be overridden by clients. The default implementation does nothing.
55      */

56     protected void doInit() {
57     }
58
59     /**
60      * Notifies the listener that the given models were opened in this model
61      * provider. This method must be called on the UI thread.
62      *
63      * @param models
64      */

65     final protected void fireSaveablesOpened(Saveable[] models) {
66         listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this,
67                 SaveablesLifecycleEvent.POST_OPEN, models, false));
68     }
69
70     /**
71      * Notifies the listener that the given models are about to be closed in
72      * this model provider. This method must be called on the UI thread.
73      *
74      * @param models
75      * @param force
76      * true if the closing may be canceled by the user
77      * @return true if the listener vetoed the closing (may be ignored if force
78      * is true)
79      */

80     final protected boolean fireSaveablesClosing(Saveable[] models,
81             boolean force) {
82         SaveablesLifecycleEvent saveablesLifecycleEvent = new SaveablesLifecycleEvent(
83                 this, SaveablesLifecycleEvent.PRE_CLOSE, models, force);
84         listener.handleLifecycleEvent(saveablesLifecycleEvent);
85         return saveablesLifecycleEvent.isVeto();
86     }
87
88     /**
89      * Notifies the listener that the given models were closed in this model
90      * provider. This method must be called on the UI thread.
91      *
92      * @param models
93      */

94     final protected void fireSaveablesClosed(Saveable[] models) {
95         listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this,
96                 SaveablesLifecycleEvent.POST_CLOSE, models, false));
97     }
98
99     /**
100      * Notifies the listener that the given models' dirty state has changed.
101      * This method must be called on the UI thread.
102      *
103      * @param models
104      */

105     final protected void fireSaveablesDirtyChanged(Saveable[] models) {
106         listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this,
107                 SaveablesLifecycleEvent.DIRTY_CHANGED, models, false));
108     }
109
110     /**
111      * Returns the saveables reachable through this provider. Changes to the
112      * list of saveables or to the saveables' dirty state must be announced
113      * using the appropriate fire* methods.
114      *
115      * @return the saveables returned by this saveables provider.
116      */

117     public abstract Saveable[] getSaveables();
118
119     /**
120      * Returns the elements representing the given saveable. It is recommended
121      * that a saveable be represented by only one element.
122      *
123      * @param saveable
124      * @return the elements representing the given saveable (array may be empty)
125      */

126     public abstract Object JavaDoc[] getElements(Saveable saveable);
127
128     /**
129      * Returns the saveable for the given element, or null if the element does
130      * not represent a saveable.
131      *
132      * @param element
133      * @return the saveable for the given element, or null
134      */

135     public abstract Saveable getSaveable(Object JavaDoc element);
136
137     /**
138      * Disposes of this saveables provider. Subclasses may extend, but must call
139      * the super implementation.
140      */

141     public void dispose() {
142         listener = null;
143     }
144
145 }
146
Popular Tags