1 19 package org.netbeans.modules.xml.multiview; 20 21 import java.util.Arrays ; 22 import javax.swing.Action ; 23 import org.netbeans.core.spi.multiview.MultiViewElementCallback; 24 import org.netbeans.core.spi.multiview.MultiViewElement; 25 import org.netbeans.core.spi.multiview.CloseOperationState; 26 import org.netbeans.core.spi.multiview.MultiViewFactory; 27 import org.openide.util.NbBundle; 28 29 import java.io.Serializable ; 30 import org.openide.actions.FileSystemAction; 31 import org.openide.util.actions.SystemAction; 32 33 36 public abstract class AbstractMultiViewElement implements MultiViewElement, Serializable { 37 static final long serialVersionUID = -1161218720923844459L; 38 39 protected XmlMultiViewDataObject dObj; 40 protected transient MultiViewElementCallback callback; 41 42 protected AbstractMultiViewElement() { 43 } 44 45 protected AbstractMultiViewElement(XmlMultiViewDataObject dObj) { 46 this.dObj = dObj; 47 } 48 49 public void setMultiViewCallback(MultiViewElementCallback callback) { 50 this.callback = callback; 51 if (dObj!=null) { 52 XmlMultiViewEditorSupport support = dObj.getEditorSupport(); 53 if (support!=null) { 54 support.setMVTC(callback.getTopComponent()); 55 support.updateDisplayName(); 56 } 57 } 58 } 59 60 public CloseOperationState canCloseElement() { 61 if (dObj == null) { 62 return CloseOperationState.STATE_OK; 63 } else if (!dObj.canClose()) { 64 return MultiViewFactory.createUnsafeCloseState(NbBundle.getMessage(AbstractMultiViewElement.class, 65 "LBL_DataObjectModified"), null, null); 66 } else { 67 return CloseOperationState.STATE_OK; 68 } 69 } 70 71 public javax.swing.Action [] getActions() { 72 Action [] actions = callback.createDefaultActions(); 73 SystemAction fsAction = SystemAction.get(FileSystemAction.class); 74 if (!Arrays.asList(actions).contains(fsAction)) { 75 Action [] newActions = new Action [actions.length+1]; 76 System.arraycopy(actions, 0, newActions, 0, actions.length); 77 newActions[actions.length] = fsAction; 78 actions = newActions; 79 } 80 return actions; 81 } 82 83 public void componentOpened() { 84 } 85 86 public void componentClosed() { 87 } 88 89 public org.openide.awt.UndoRedo getUndoRedo() { 90 return dObj ==null ? null : dObj.getEditorSupport().getUndoRedo0(); 91 } 92 } 93 | Popular Tags |