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.SectionView; 25 import org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor; 26 import org.openide.loaders.DataObject; 27 import org.openide.util.WeakListeners; 28 import org.openide.util.lookup.ProxyLookup; 29 30 import java.beans.PropertyChangeEvent ; 31 import java.beans.PropertyChangeListener ; 32 import java.beans.PropertyVetoException ; 33 34 43 public abstract class ToolBarMultiViewElement extends AbstractMultiViewElement { 44 private ToolBarDesignEditor editor; 45 46 private PropertyChangeListener listener = new PropertyChangeListener () { 47 public void propertyChange(PropertyChangeEvent evt) { 48 if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && editor != null) { 49 Utils.runInAwtDispatchThread(new Runnable () { 50 public void run() { 51 if (null != callback){ 52 callback.getTopComponent().setDisplayName(dObj.getEditorSupport().messageName()); 53 } 54 } 55 }); 56 } 57 } 58 }; 59 60 public ToolBarMultiViewElement(final XmlMultiViewDataObject dObj) { 61 super(dObj); 62 dObj.addPropertyChangeListener(WeakListeners.propertyChange(listener, dObj)); 63 } 64 65 protected void setVisualEditor(ToolBarDesignEditor editor) { 66 this.editor=editor; 67 } 68 69 public CloseOperationState canCloseElement() { 70 if (!editorValidate()) { 71 return MultiViewFactory.createUnsafeCloseState(ToolBarDesignEditor.PROPERTY_FLUSH_DATA, null, null); 72 } else { 73 return super.canCloseElement(); 74 } 75 } 76 77 private boolean editorValidate() { 78 try { 79 editor.fireVetoableChange(ToolBarDesignEditor.PROPERTY_FLUSH_DATA, this, null); 80 return true; 81 } catch (PropertyVetoException e) { 82 return false; 83 } 84 } 85 86 public void componentActivated() { 87 editor.componentActivated(); 88 } 89 90 public void componentClosed() { 91 editor.componentClosed(); 92 } 93 94 public void componentDeactivated() { 95 editor.componentDeactivated(); 96 } 97 98 public void componentHidden() { 99 editor.componentHidden(); 100 dObj.setActiveMultiViewElement(null); 101 } 102 103 public void componentOpened() { 104 editor.componentOpened(); 105 } 106 107 public void componentShowing() { 108 if (editorValidate()) { 109 editor.componentShowing(); 110 dObj.setActiveMultiViewElement(this); 111 } 112 } 113 114 public org.openide.util.Lookup getLookup() { 115 return new ProxyLookup(new org.openide.util.Lookup[] { 116 dObj.getNodeDelegate().getLookup() 117 }); 118 } 119 120 public javax.swing.JComponent getToolbarRepresentation() { 121 return editor.getStructureView(); 122 } 123 124 public javax.swing.JComponent getVisualRepresentation() { 125 return editor; 126 } 127 129 public abstract SectionView getSectionView(); 130 131 } 132 | Popular Tags |