KickJava   Java API By Example, From Geeks To Geeks.

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


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
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 JavaDoc;
31 import java.beans.PropertyChangeListener JavaDoc;
32 import java.beans.PropertyVetoException JavaDoc;
33
34 /**
35  * An implementation of <code>MultiViewElement</code> that is specific to
36  * <code>XmlMultiViewDataObject</code>.
37  *
38  * @see org.netbeans.modules.xml.multiview.ui.ToolBarDesignEditor
39  *
40  * Created on October 5, 2004, 1:35 PM
41  * @author mkuchtiak
42  */

43 public abstract class ToolBarMultiViewElement extends AbstractMultiViewElement {
44     private ToolBarDesignEditor editor;
45     
46     private PropertyChangeListener JavaDoc listener = new PropertyChangeListener JavaDoc() {
47         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
48             if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && editor != null) {
49                 Utils.runInAwtDispatchThread(new Runnable JavaDoc() {
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 JavaDoc 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 JavaDoc getToolbarRepresentation() {
121         return editor.getStructureView();
122     }
123     
124     public javax.swing.JComponent JavaDoc getVisualRepresentation() {
125         return editor;
126     }
127     /** Enable to get the SectionView included in this MultiView Element
128      */

129     public abstract SectionView getSectionView();
130     
131 }
132
Popular Tags