KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 JavaDoc;
30 import java.beans.PropertyChangeListener JavaDoc;
31 import java.beans.PropertyVetoException JavaDoc;
32
33 /**
34  * XmlMultiviewElement.java
35  *
36  * Created on October 5, 2004, 1:35 PM
37  * @author mkuchtiak
38  */

39 public abstract class TreePanelMultiViewElement extends AbstractMultiViewElement {
40     private TreePanelDesignEditor editor;
41
42     private PropertyChangeListener JavaDoc listener = new PropertyChangeListener JavaDoc() {
43         public void propertyChange(PropertyChangeEvent JavaDoc evt) {
44             if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName()) && editor != null) {
45                 Utils.runInAwtDispatchThread(new Runnable JavaDoc() {
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 JavaDoc 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 JavaDoc getToolbarRepresentation() {
105         //return editor.getStructureView();
106
return new javax.swing.JPanel JavaDoc();
107     }
108     
109     public javax.swing.JComponent JavaDoc getVisualRepresentation() {
110         return editor;
111     }
112
113 }
114
Popular Tags