1 9 10 package org.netbeans.modules.web.jsf; 11 12 import java.awt.Image ; 13 import java.io.IOException ; 14 import java.io.Serializable ; 15 import javax.swing.JComponent ; 16 import javax.swing.JEditorPane ; 17 import javax.swing.JPanel ; 18 import javax.swing.text.Document ; 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 38 public class JSFConfigMultiviewDescriptor implements MultiViewDescription, Serializable { 39 static final long serialVersionUID = -6305897237371751564L; 40 41 private JSFConfigEditorContext context; 42 43 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 getDisplayName() { 53 return "XML"; 54 } 55 56 public Image getIcon() { 57 return null; 58 } 59 60 public HelpCtx getHelpCtx() { 61 return null; 62 } 63 64 public String 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 { 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 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 getVisualRepresentation() { 106 return tc; 107 } 108 109 public JComponent getToolbarRepresentation() { 110 if (toolbar == null) { 111 JEditorPane pane = editor.getEditorPane(); 112 if (pane != null) { 113 Document 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 (); 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 [] getActions() { 165 return editor.getActions(); 166 } 167 168 private void writeObject(java.io.ObjectOutputStream out) throws IOException { 169 out.writeObject(context); 170 } 171 172 private void readObject(java.io.ObjectInputStream in) throws IOException , ClassNotFoundException { 173 Object object = in.readObject(); 174 if (! (object instanceof JSFConfigEditorContext)) 175 throw new ClassNotFoundException ("JSFConfigEditorContext expected but not found"); 176 context = (JSFConfigEditorContext) object; 177 init(); 178 } 179 } 180 181 } 182 | Popular Tags |