1 19 20 package org.netbeans.modules.form; 21 22 import java.awt.Component ; 23 import java.awt.Window ; 24 import java.awt.event.WindowAdapter ; 25 import java.awt.event.WindowEvent ; 26 27 import org.openide.nodes.*; 28 import org.openide.cookies.*; 29 import org.openide.actions.*; 30 import org.openide.util.actions.SystemAction; 31 import org.openide.loaders.DataObject; 32 33 38 39 public class FormNode extends AbstractNode implements FormCookie { 40 41 private FormModel formModel; 42 43 protected FormNode(Children children, FormModel formModel) { 44 super(children); 45 this.formModel = formModel; 46 getCookieSet().add(this); 47 } 48 49 public final FormModel getFormModel() { 51 return formModel; 52 } 53 54 public final Node getOriginalNode() { 56 return this; 57 } 58 59 public Node.Cookie getCookie(Class type) { 60 Node.Cookie cookie = super.getCookie(type); 61 if (cookie == null 62 && (DataObject.class.isAssignableFrom(type) 63 || SaveCookie.class.isAssignableFrom(type) 64 || CloseCookie.class.isAssignableFrom(type) 65 || PrintCookie.class.isAssignableFrom(type))) 66 { 67 FormDataObject fdo = FormEditor.getFormDataObject(formModel); 68 if (fdo != null) 69 cookie = fdo.getCookie(type); 70 } 71 return cookie; 72 } 73 74 void updateCookies() { 77 super.fireCookieChange(); 78 } 79 80 public javax.swing.Action [] getActions(boolean context) { 81 if (systemActions == null) systemActions = new SystemAction[] { 83 SystemAction.get(PropertiesAction.class) 84 }; 85 return systemActions; 86 } 87 88 public Component getCustomizer() { 89 Component customizer = createCustomizer(); 90 if (customizer instanceof Window ) { 91 FormEditor formEditor = FormEditor.getFormEditor(formModel); 94 if (formEditor != null) { 95 Window customizerWindow = (Window ) customizer; 96 formEditor.registerFloatingWindow(customizerWindow); 97 customizerWindow.addWindowListener(new WindowAdapter () { 99 public void windowClosing(WindowEvent e) { 100 if (e.getSource() instanceof Window ) { 101 Window window = (Window ) e.getSource(); 102 FormEditor formEditor = FormEditor.getFormEditor(formModel); 103 if (formEditor != null) 104 formEditor.unregisterFloatingWindow(window); 105 window.removeWindowListener(this); 106 } 107 } 108 }); 109 } 110 } 111 return customizer; 112 } 113 114 protected Component createCustomizer() { 116 return null; 117 } 118 119 120 public void firePropertyChangeHelper(String name, 121 Object oldValue, Object newValue) { 122 super.firePropertyChange(name, oldValue, newValue); 123 } 124 125 128 void updateChildren() { 129 Children children = getChildren(); 130 if (children instanceof FormNodeChildren) 131 ((FormNodeChildren)children).updateKeys(); 132 } 133 134 protected abstract static class FormNodeChildren extends Children.Keys { 137 protected void updateKeys() {} 138 } 139 140 147 public Node.Handle getHandle() { 148 return new Handle(); 149 } 150 151 static class Handle implements Node.Handle { 152 static final long serialVersionUID = 1; 153 public Node getNode() throws java.io.IOException { 154 return new ClosingNode(); 155 } 156 } 157 158 static class ClosingNode extends AbstractNode implements Runnable { 159 ClosingNode() { 160 super(Children.LEAF); 161 } 162 public String getName() { 163 java.awt.EventQueue.invokeLater(this); 164 return super.getName(); 165 } 166 public Node.PropertySet[] getPropertySets() { 167 java.awt.EventQueue.invokeLater(this); 168 return super.getPropertySets(); 169 } 170 public void run() { 171 this.fireNodeDestroyed(); 172 } 173 } 174 } 175 | Popular Tags |