1 19 20 package org.netbeans.modules.xml.multiview; 21 22 import org.netbeans.core.spi.multiview.CloseOperationState; 23 import org.netbeans.core.spi.multiview.MultiViewFactory; 24 import org.netbeans.modules.xml.multiview.ui.TreePanelDesignEditor; 25 import org.openide.loaders.DataObject; 26 import org.openide.util.WeakListeners; 27 import org.openide.util.lookup.ProxyLookup; 28 29 import java.beans.PropertyChangeEvent ; 30 import java.beans.PropertyChangeListener ; 31 import java.beans.PropertyVetoException ; 32 33 39 public abstract class TreePanelMultiViewElement extends AbstractMultiViewElement { 40 private TreePanelDesignEditor editor; 41 42 private PropertyChangeListener listener = new PropertyChangeListener () { 43 public void propertyChange(PropertyChangeEvent evt) { 44 if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && editor != null) { 45 Utils.runInAwtDispatchThread(new Runnable () { 46 public void run() { 47 callback.getTopComponent().setDisplayName(dObj.getEditorSupport().messageName()); 48 } 49 }); 50 } 51 } 52 }; 53 54 public TreePanelMultiViewElement(final XmlMultiViewDataObject dObj) { 55 super(dObj); 56 dObj.addPropertyChangeListener(WeakListeners.propertyChange(listener, dObj)); 57 } 58 59 protected void setVisualEditor(TreePanelDesignEditor editor) { 60 this.editor=editor; 61 } 62 63 public CloseOperationState canCloseElement() { 64 try { 65 editor.fireVetoableChange(TreePanelDesignEditor.PROPERTY_FLUSH_DATA, this, null); 66 } catch (PropertyVetoException e) { 67 return MultiViewFactory.createUnsafeCloseState(TreePanelDesignEditor.PROPERTY_FLUSH_DATA, null, null); 68 } 69 return super.canCloseElement(); 70 } 71 72 public void componentActivated() { 73 editor.componentActivated(); 74 } 75 76 public void componentClosed() { 77 editor.componentClosed(); 78 } 79 80 public void componentDeactivated() { 81 editor.componentDeactivated(); 82 } 83 84 public void componentHidden() { 85 editor.componentHidden(); 86 dObj.setActiveMultiViewElement(null); 87 } 88 89 public void componentOpened() { 90 editor.componentOpened(); 91 } 92 93 public void componentShowing() { 94 editor.componentShowing(); 95 dObj.setActiveMultiViewElement(this); 96 } 97 98 public org.openide.util.Lookup getLookup() { 99 return new ProxyLookup(new org.openide.util.Lookup[] { 100 dObj.getNodeDelegate().getLookup() 101 }); 102 } 103 104 public javax.swing.JComponent getToolbarRepresentation() { 105 return new javax.swing.JPanel (); 107 } 108 109 public javax.swing.JComponent getVisualRepresentation() { 110 return editor; 111 } 112 113 } 114 | Popular Tags |