1 9 10 package org.netbeans.modules.web.jsf.navigation; 11 12 import java.awt.Image ; 13 import java.io.IOException ; 14 import java.io.Serializable ; 15 import javax.swing.Action ; 16 import javax.swing.JComponent ; 17 import javax.swing.JLabel ; 18 import javax.swing.JToolBar ; 19 import javax.swing.border.EmptyBorder ; 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 36 public class JSFPageFlowMultiviewDescriptor implements MultiViewDescription, Serializable { 37 38 private static final long serialVersionUID = -6305897237371751567L; 39 40 private JSFConfigEditorContext context; 41 42 43 46 public JSFPageFlowMultiviewDescriptor() { 47 } 48 49 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 getDisplayName() { 62 return "PageFlow"; 63 } 64 65 public Image getIcon() { 66 return null; 67 } 68 69 public HelpCtx getHelpCtx() { 70 return null; 71 } 72 73 public String 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 { 83 private transient PageFlowView tc; 85 private transient JComponent toolbar; 86 private static final long serialVersionUID = -6305897237371751567L; 87 private JSFConfigEditorContext context; 88 89 90 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 106 } 107 108 public JComponent getVisualRepresentation() { 109 return tc; 110 } 111 112 public JComponent 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 [] 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 } 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 out) throws IOException { 191 out.writeObject(context); 192 } 193 194 private void readObject(java.io.ObjectInputStream in) throws IOException , ClassNotFoundException { 195 Object object = in.readObject(); 196 if (! (object instanceof JSFConfigEditorContext)) 197 throw new ClassNotFoundException ("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 |