KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > multiview > AbstractMultiViewElement


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.xml.multiview;
20
21 import java.util.Arrays JavaDoc;
22 import javax.swing.Action JavaDoc;
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 JavaDoc;
30 import org.openide.actions.FileSystemAction;
31 import org.openide.util.actions.SystemAction;
32
33 /**
34  * @author pfiala
35  */

36 public abstract class AbstractMultiViewElement implements MultiViewElement, Serializable JavaDoc {
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 JavaDoc[] getActions() {
72         Action JavaDoc[] actions = callback.createDefaultActions();
73         SystemAction fsAction = SystemAction.get(FileSystemAction.class);
74         if (!Arrays.asList(actions).contains(fsAction)) {
75             Action JavaDoc[] newActions = new Action JavaDoc[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