KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > jsf > JSFConfigMultiviewDescriptor


1 /*
2  * JSFConfigMultiviewDescriptor.java
3  *
4  * Created on February 7, 2007, 5:22 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;
11
12 import java.awt.Image JavaDoc;
13 import java.io.IOException JavaDoc;
14 import java.io.Serializable JavaDoc;
15 import javax.swing.JComponent JavaDoc;
16 import javax.swing.JEditorPane JavaDoc;
17 import javax.swing.JPanel JavaDoc;
18 import javax.swing.text.Document JavaDoc;
19 import org.netbeans.core.spi.multiview.CloseOperationState;
20 import org.netbeans.core.spi.multiview.MultiViewDescription;
21 import org.netbeans.core.spi.multiview.MultiViewElement;
22 import org.netbeans.core.spi.multiview.MultiViewElementCallback;
23 import org.netbeans.modules.web.jsf.api.editor.JSFConfigEditorContext;
24 import org.openide.awt.UndoRedo;
25 import org.openide.filesystems.FileObject;
26 import org.openide.loaders.DataObject;
27 import org.openide.loaders.DataObjectNotFoundException;
28 import org.openide.text.CloneableEditor;
29 import org.openide.text.NbDocument;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.Lookup;
32 import org.openide.windows.TopComponent;
33
34 /**
35  *
36  * @author petr
37  */

38 public class JSFConfigMultiviewDescriptor implements MultiViewDescription, Serializable JavaDoc{
39     static final long serialVersionUID = -6305897237371751564L;
40     
41     private JSFConfigEditorContext context;
42     
43     /** Creates a new instance of StrutsConfigMultiviewDescriptor */
44     public JSFConfigMultiviewDescriptor(JSFConfigEditorContext context) {
45         this.context = context;
46     }
47     
48     public int getPersistenceType() {
49         return TopComponent.PERSISTENCE_ONLY_OPENED;
50     }
51     
52     public String JavaDoc getDisplayName() {
53         return "XML";
54     }
55     
56     public Image JavaDoc getIcon() {
57         return null;
58     }
59     
60     public HelpCtx getHelpCtx() {
61         return null;
62     }
63     
64     public String JavaDoc preferredID() {
65         return "XML";
66     }
67     
68     public MultiViewElement createElement() {
69         return new JSFConfigMultiviewElement(context);
70     }
71     
72     
73     
74     class JSFConfigMultiviewElement implements MultiViewElement, Serializable JavaDoc {
75         static final long serialVersionUID = -6305897237371751564L;
76         
77         private transient TopComponent tc;
78         private JSFConfigEditorContext context;
79         private transient CloneableEditor editor;
80         private transient JComponent JavaDoc toolbar;
81         private transient JSFConfigDataObject jsfDataObject;
82         
83         public JSFConfigMultiviewElement(JSFConfigEditorContext context) {
84             this.context = context;
85             init();
86         }
87         
88         private void init() {
89             try {
90                 org.openide.loaders.DataObject dObject = org.openide.loaders.DataObject.find(context.getFacesConfigFile());
91
92                 jsfDataObject = (org.netbeans.modules.web.jsf.JSFConfigDataObject) dObject;
93                 editor = new org.openide.text.CloneableEditor(jsfDataObject.getEditorSupport());
94                 tc = new org.netbeans.modules.web.jsf.JSFConfigEditorTopComponent(context,
95                                                                                   null,
96                                                                                   editor);
97             }
98             catch (DataObjectNotFoundException ex) {
99                 java.util.logging.Logger.getLogger("global").log(java.util.logging.Level.SEVERE,
100                                                                  ex.getMessage(),
101                                                                  ex);
102             }
103 }
104         
105         public JComponent JavaDoc getVisualRepresentation() {
106             return tc;
107         }
108         
109         public JComponent JavaDoc getToolbarRepresentation() {
110             if (toolbar == null) {
111                 JEditorPane JavaDoc pane = editor.getEditorPane();
112                 if (pane != null) {
113                     Document JavaDoc doc = pane.getDocument();
114                     if (doc instanceof NbDocument.CustomToolbar)
115                         toolbar = ((NbDocument.CustomToolbar) doc).createToolbar(pane);
116                 }
117                 if (toolbar == null)
118                     toolbar = new JPanel JavaDoc();
119             }
120             return toolbar;
121         }
122         
123         
124         public Lookup getLookup() {
125             return tc.getLookup();
126         }
127         
128         public void componentOpened() {
129             
130         }
131         
132         public void componentClosed() {
133             
134         }
135         
136         public void componentShowing() {
137             
138         }
139         
140         public void componentHidden() {
141             
142         }
143         
144         public void componentActivated() {
145             
146         }
147         
148         public void componentDeactivated() {
149             
150         }
151         
152         public UndoRedo getUndoRedo() {
153             return editor.getUndoRedo();
154         }
155         
156         public void setMultiViewCallback(MultiViewElementCallback callback) {
157             context.setMultiViewTopComponent(callback.getTopComponent());
158         }
159         
160         public CloseOperationState canCloseElement() {
161             return CloseOperationState.STATE_OK;
162         }
163         
164         public javax.swing.Action JavaDoc[] getActions() {
165             return editor.getActions();
166         }
167         
168         private void writeObject(java.io.ObjectOutputStream JavaDoc out) throws IOException JavaDoc {
169             out.writeObject(context);
170         }
171         
172         private void readObject(java.io.ObjectInputStream JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
173             Object JavaDoc object = in.readObject();
174             if (! (object instanceof JSFConfigEditorContext))
175                 throw new ClassNotFoundException JavaDoc("JSFConfigEditorContext expected but not found");
176             context = (JSFConfigEditorContext) object;
177             init();
178         }
179     }
180     
181 }
182
Popular Tags