1 19 package org.netbeans.modules.xml.core; 20 21 import java.beans.*; 22 23 import javax.xml.transform.Source ; 24 25 import org.xml.sax.*; 26 27 import org.openide.awt.HtmlBrowser; 28 import org.openide.filesystems.*; 29 import org.openide.loaders.*; 30 import org.openide.util.*; 31 import org.openide.nodes.*; 32 import org.openide.cookies.*; 33 import org.openide.actions.*; 34 import org.openide.windows.CloneableOpenSupport; 35 import org.openide.util.actions.SystemAction; 36 37 import org.netbeans.modules.xml.core.text.TextEditorSupport; 38 import org.netbeans.modules.xml.core.sync.*; 39 import org.netbeans.modules.xml.core.cookies.*; 40 import org.netbeans.modules.xml.core.settings.*; 41 42 import org.netbeans.spi.xml.cookies.*; 43 44 51 public final class XMLDataObject extends org.openide.loaders.XMLDataObject 52 implements XMLDataObjectLook, PropertyChangeListener { 53 54 55 private static final long serialVersionUID = 9153823984913876866L; 56 57 58 public static final String MIME_TYPE = "text/xml"; 60 61 private XMLSyncSupport sync; 62 63 64 private final DataObjectCookieManager cookieManager; 65 66 67 71 72 77 public XMLDataObject (final FileObject fo, MultiFileLoader loader) throws DataObjectExistsException { 78 super (fo, loader); 79 80 CookieSet set = getCookieSet(); 81 set.add (cookieManager = new DataObjectCookieManager (this, set)); 82 83 sync = new XMLSyncSupport(this); 84 85 TextEditorSupport.TextEditorSupportFactory editorFactory = 86 TextEditorSupport.findEditorSupportFactory (this, MIME_TYPE); 87 editorFactory.registerCookies (set); 88 89 CookieSet.Factory viewCookieFactory = new ViewCookieFactory(); 90 set.add (ViewCookie.class, viewCookieFactory); 91 92 InputSource is = DataObjectAdapters.inputSource (this); 93 set.add (new CheckXMLSupport (is)); 95 set.add (new ValidateXMLSupport (is)); 96 97 Source source = DataObjectAdapters.source (this); 99 set.add (new TransformableSupport (source)); 100 101 set.add (new ScenarioSupport (this)); 103 104 new CookieManager (this, set, XMLCookieFactoryCreator.class); 105 106 this.addPropertyChangeListener (this); } 108 109 110 111 117 118 119 121 protected Node createNodeDelegate () { 122 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("--> XMLDataObject.createNodeDelegate: this = " + this); 123 124 DataNodeCreator dataNodeCreator = (DataNodeCreator) Lookup.getDefault().lookup (DataNodeCreator.class); 125 Node dataNode = null; 126 127 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("-*- XMLD O .createNodeDelegate: dataNodeCreator = " + dataNodeCreator); 128 129 if ( dataNodeCreator != null ) { 130 dataNode = dataNodeCreator.createDataNode (this); 131 } else { 132 dataNode = new XMLDataNode (this); 133 } 134 135 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("<-- XMLDataObject.createNodeDelegate: dataNode = " + dataNode); 136 137 return dataNode; 138 } 139 140 143 Node createDefaultNodeDelegate () { 144 return super.createNodeDelegate(); } 146 147 148 149 protected EditorCookie createEditorCookie () { 151 return null; 152 } 153 154 155 156 public void setModified (boolean state) { 157 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("XMLDataObject:setModified: state = " + state); 159 super.setModified (state); 160 } 161 162 163 164 public org.openide.nodes.Node.Cookie getCookie(Class klass) { 165 166 Node.Cookie cake = null; 167 boolean change = false; 168 169 if (SaveCookie.class.equals (klass) ) { 170 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("XMLDataObject::getCookie"); } 172 173 synchronized (this) { 176 cake = super.getCookie (klass); 177 178 if ( ( cake == null ) && 179 ( CloneableOpenSupport.class == klass ) ) { cake = super.getCookie (OpenCookie.class); 181 } 182 } 183 184 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("XMLDataOObject::getCookie: class = " + klass + " => " + cake); 186 return cake; 187 } 188 189 190 public DataObjectCookieManager getCookieManager() { 191 return cookieManager; 192 } 193 194 195 201 202 210 217 public synchronized void updateDocument () { 218 219 Thread.dumpStack(); 221 223 } 224 225 public Synchronizator getSyncInterface() { 226 return sync; 227 } 228 229 230 231 232 233 239 240 243 public void propertyChange (PropertyChangeEvent e) { 244 245 if ( Util.THIS.isLoggable() ) Util.THIS.debug ("event " + e.getPropertyName()); 247 if (org.openide.loaders.XMLDataObject.PROP_DOCUMENT.equals (e.getPropertyName())) { 248 249 if (e.getOldValue() == e.getNewValue()) return; 252 sync.representationChanged(FileObject.class); 253 } 254 } 255 256 257 public HelpCtx getHelpCtx() { 258 return HelpCtx.DEFAULT_HELP; 260 } 261 262 266 269 public static class XMLDataNode extends DataNode { 270 271 272 public XMLDataNode (XMLDataObject obj) { 273 super (obj, Children.LEAF); 274 275 setIconBaseWithExtension ("org/netbeans/modules/xml/core/resources/xmlObject.gif"); setShortDescription (Util.THIS.getString ("PROP_XMLDataNode_description")); 277 } 278 279 public SystemAction getDefaultAction() { 280 CoreSettings settings = CoreSettings.getDefault(); 281 SystemAction actions[] = getActions(); 282 SystemAction system = SystemAction.get (EditAction.class); 283 284 return settings.getDefaultAction (actions, system); 285 } 286 287 } 289 290 294 297 private class ViewCookieFactory implements CookieSet.Factory { 298 299 300 public Node.Cookie createCookie (Class klass) { 301 if (klass == ViewCookie.class) { 302 return new ViewSupport (XMLDataObject.this.getPrimaryEntry()); 303 } else { 304 return null; 305 } 306 } 307 308 } 310 311 315 318 private static final class ViewSupport implements ViewCookie { 319 320 321 private MultiDataObject.Entry primary; 322 323 324 public ViewSupport (MultiDataObject.Entry primary) { 325 this.primary = primary; 326 } 327 328 330 public void view () { 331 try { 332 HtmlBrowser.URLDisplayer.getDefault().showURL(primary.getFile().getURL()); 333 } catch (FileStateInvalidException e) { 334 } 335 } 336 337 } 339 340 341 345 348 public static interface DataNodeCreator { 349 350 352 public DataNode createDataNode (XMLDataObject xmlDO); 353 354 } 356 357 358 362 365 public static interface XMLCookieFactoryCreator extends CookieFactoryCreator { 366 367 } 369 } 370 | Popular Tags |