KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > navigation > JSFPageFlowMultiviewDescriptor


1 /*
2  * JSFTestMultiviewDescriptor.java
3  *
4  * Created on February 7, 2007, 6:25 PM
5  *
6  * To change this template, choose Tools | Template Manager
7  * and open the template in the editor.
8  */

9
10 package org.netbeans.modules.web.jsf.navigation;
11
12 import java.awt.Image JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.Serializable JavaDoc;
15 import javax.swing.Action JavaDoc;
16 import javax.swing.JComponent JavaDoc;
17 import javax.swing.JLabel JavaDoc;
18 import javax.swing.JToolBar JavaDoc;
19 import javax.swing.border.EmptyBorder JavaDoc;
20 import org.netbeans.core.spi.multiview.CloseOperationState;
21 import org.netbeans.core.spi.multiview.MultiViewDescription;
22 import org.netbeans.core.spi.multiview.MultiViewElement;
23 import org.netbeans.core.spi.multiview.MultiViewElementCallback;
24 import org.netbeans.modules.web.jsf.api.editor.JSFConfigEditorContext;
25 import org.openide.awt.UndoRedo;
26 import org.openide.loaders.DataObject;
27 import org.openide.loaders.DataObjectNotFoundException;
28 import org.openide.util.HelpCtx;
29 import org.openide.util.Lookup;
30 import org.openide.windows.TopComponent;
31
32 /**
33  *
34  * @author Joelle Lam
35  */

36 public class JSFPageFlowMultiviewDescriptor implements MultiViewDescription, Serializable JavaDoc{
37     
38     private static final long serialVersionUID = -6305897237371751567L;
39     
40     private JSFConfigEditorContext context;
41     
42     
43     /**
44      * This is the multiview descripture which defines a new pane in the faces configuration xml multiview editor.
45      */

46     public JSFPageFlowMultiviewDescriptor() {
47     }
48     
49     /**
50      * This is the multiview descripture which defines a new pane in the faces configuration xml multiview editor.
51      * @param context the JSFConfigEditorContext
52      **/

53     public JSFPageFlowMultiviewDescriptor(JSFConfigEditorContext context) {
54         this.context = context;
55     }
56     
57     public int getPersistenceType() {
58         return TopComponent.PERSISTENCE_ONLY_OPENED;
59     }
60     
61     public String JavaDoc getDisplayName() {
62         return "PageFlow";
63     }
64     
65     public Image JavaDoc getIcon() {
66         return null;
67     }
68     
69     public HelpCtx getHelpCtx() {
70         return null;
71     }
72     
73     public String JavaDoc preferredID() {
74         return "pageflow";
75     }
76     
77     public MultiViewElement createElement() {
78         return new PageFlowElement(context);
79     }
80     
81     
82     static class PageFlowElement implements MultiViewElement, Serializable JavaDoc {
83         // private transient JScrollPane panel;
84
private transient PageFlowView tc;
85         private transient JComponent JavaDoc toolbar;
86         private static final long serialVersionUID = -6305897237371751567L;
87         private JSFConfigEditorContext context;
88         
89         
90         // public PageFlowElement() {
91
// }
92

93         public PageFlowElement(JSFConfigEditorContext context) {
94             this.context = context;
95             init();
96         }
97         
98         private void init() {
99             
100             getTopComponent().setName(context.getFacesConfigFile().getName());
101             // panel = new JScrollPane(tc);
102
// panel.setName(context.getFacesConfigFile().getName());
103
// this.setName(context.getFacesConfigFile().getName());
104
// add(panel, BorderLayout.CENTER);
105

106         }
107         
108         public JComponent JavaDoc getVisualRepresentation() {
109             return tc;
110         }
111         
112         public JComponent JavaDoc getToolbarRepresentation() {
113             if (toolbar == null) {
114                 toolbar = getTopComponent().getToolbarRepresentation();
115             }
116             return toolbar;
117         }
118         
119         private PageFlowView getTopComponent() {
120             if( tc == null ) {
121                 tc = new PageFlowView(context);
122             }
123             return tc;
124         }
125         
126         public Action JavaDoc[] getActions() {
127             try {
128                 DataObject dataObject = org.openide.loaders.DataObject.find(context.getFacesConfigFile());
129                 
130                 return dataObject.getNodeDelegate().getActions(false);
131             } catch (DataObjectNotFoundException ex) {
132                 java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE,
133                         ex.getMessage(),
134                         ex);
135             }
136             return null;
137             
138             
139         }
140         
141         public Lookup getLookup() {
142             return tc.getLookup();
143             // try {
144
//
145
// /* I needed to add the top component's lookup to the multiview elements lookup inorder to have an associated palette.*/
146
// DataObject dataObject = org.openide.loaders.DataObject.find(context.getFacesConfigFile());
147
// return new ProxyLookup(new Lookup[] {dataObject.getLookup(), tc.getLookup()});
148
//
149
// } catch (DataObjectNotFoundException ex) {
150
// java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE,
151
// ex.getMessage(),
152
// ex);
153
// }
154
// return null;
155
}
156         
157         public void componentOpened() {
158             
159         }
160         
161         public void componentClosed() {
162             
163         }
164         
165         public void componentShowing() {
166             
167         }
168         
169         public void componentHidden() {
170             
171         }
172         
173         public void componentActivated() {
174             
175         }
176         
177         public void componentDeactivated() {
178             
179         }
180         
181         
182         public void setMultiViewCallback(MultiViewElementCallback callback) {
183             context.setMultiViewTopComponent(callback.getTopComponent());
184         }
185         
186         public CloseOperationState canCloseElement() {
187             return CloseOperationState.STATE_OK;
188         }
189         
190         private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
191             out.writeObject(context);
192         }
193         
194         private void readObject(java.io.ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
195             Object JavaDoc object = in.readObject();
196             if (! (object instanceof JSFConfigEditorContext))
197                 throw new ClassNotFoundException JavaDoc("JSFConfigEditorContext expected but not found");
198             context = (JSFConfigEditorContext) object;
199             init();
200         }
201         
202         public UndoRedo getUndoRedo() {
203             return context.getUndoRedo();
204         }
205         
206     }
207 }
208
Popular Tags