KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > schema > abe > ABEBaseDropPanel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.schema.abe;
21
22 import java.awt.dnd.DropTarget JavaDoc;
23 import java.awt.dnd.DropTargetDragEvent JavaDoc;
24 import java.awt.dnd.DropTargetDropEvent JavaDoc;
25 import java.awt.dnd.DropTargetEvent JavaDoc;
26 import java.awt.dnd.DropTargetListener JavaDoc;
27 import java.awt.event.ComponentEvent JavaDoc;
28 import java.awt.event.ComponentListener JavaDoc;
29 import java.awt.event.ContainerEvent JavaDoc;
30 import java.awt.event.ContainerListener JavaDoc;
31 import java.awt.event.HierarchyEvent JavaDoc;
32 import java.awt.event.HierarchyListener JavaDoc;
33 import java.beans.PropertyChangeEvent JavaDoc;
34 import java.beans.PropertyChangeListener JavaDoc;
35 import javax.swing.JPanel JavaDoc;
36 import javax.swing.event.AncestorEvent JavaDoc;
37 import javax.swing.event.AncestorListener JavaDoc;
38 import org.netbeans.modules.xml.axi.AXIComponent;
39 import org.netbeans.modules.xml.schema.abe.nodes.ABEAbstractNode;
40 import org.netbeans.modules.xml.xam.ui.XAMUtils;
41
42 /**
43  *
44  *
45  * @author Todd Fast, todd.fast@sun.com
46  */

47 public abstract class ABEBaseDropPanel extends JPanel JavaDoc {
48     protected static final long serialVersionUID = 7526472295622776147L;
49     protected InstanceUIContext context;
50     protected boolean firstTimeRename = false;
51     /**
52      *
53      *
54      */

55     public ABEBaseDropPanel(InstanceUIContext context) {
56         super();
57         this.context = context;
58         this.context.addPropertyChangeListener(new PropertyChangeListener JavaDoc(){
59             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
60                 if(evt.getPropertyName().equals(InstanceDesignConstants.
61                         PROP_SHUTDOWN)){
62                     ABEBaseDropPanel.this.context.removePropertyChangeListener(this);
63                 }
64             }
65         });
66         initialize();
67     }
68     
69     
70     public boolean isWritable(){
71         return XAMUtils.isWritable(context.getAXIModel());
72     }
73     
74     /**
75      *
76      *
77      */

78     private void initialize() {
79         // Set up the drop target to accept items from the palette
80
//allow DnD only if the model is writable
81
setDropTarget(
82                 new DropTarget JavaDoc(this,
83                 new DropTargetListener JavaDoc() {
84             public void dragEnter(DropTargetDragEvent JavaDoc event) {
85                 if(!isWritable())
86                     return;
87                 setActive(true);
88                 ABEBaseDropPanel.this.dragEnter(event);
89             }
90             
91             public void dragExit(DropTargetEvent JavaDoc event) {
92                 if(!isWritable())
93                     return;
94                 setActive(false);
95                 ABEBaseDropPanel.this.dragExit(event);
96             }
97             
98             public void dragOver(DropTargetDragEvent JavaDoc event) {
99                 if(!isWritable())
100                     return;
101                 ABEBaseDropPanel.this.dragOver(event);
102             }
103             
104             public void drop(DropTargetDropEvent JavaDoc event) {
105                 if(!isWritable())
106                     return;
107                 setActive(false);
108                 ABEBaseDropPanel.this.drop(event);
109             }
110             
111             public void dropActionChanged(DropTargetDragEvent JavaDoc event) {
112                 if(!isWritable())
113                     return;
114                 ABEBaseDropPanel.this.dropActionChanged(event);
115             }
116         })
117         );
118         
119     }
120     
121     
122     
123     
124     ////////////////////////////////////////////////////////////////////////////
125
// Drag methods
126
////////////////////////////////////////////////////////////////////////////
127

128     /**
129      *
130      *
131      */

132     public boolean isActive() {
133         return active;
134     }
135     
136     
137     /**
138      *
139      *
140      */

141     public void setActive(boolean value) {
142         if (value!=active) {
143             boolean oldValue=active;
144             active=value;
145             
146             handleActive(value);
147             firePropertyChange(PROP_ACTIVE,oldValue,active);
148         }
149     }
150     
151     
152     /**
153      *
154      *
155      */

156     protected void handleActive(boolean value) {
157         // Do nothing
158
}
159     
160     
161     /**
162      *
163      *
164      */

165     public void dragEnter(DropTargetDragEvent JavaDoc event) {
166         event.rejectDrag();
167         // Do nothing
168
}
169     
170     
171     /**
172      *
173      *
174      */

175     public void dragExit(DropTargetEvent JavaDoc event) {
176         // Do nothing
177
}
178     
179     
180     /**
181      *
182      *
183      */

184     public void dragOver(DropTargetDragEvent JavaDoc event) {
185         event.rejectDrag();
186         // Do nothing
187
}
188     
189     
190     /**
191      *
192      *
193      */

194     public void drop(DropTargetDropEvent JavaDoc event) {
195         event.rejectDrop();
196         // Do nothing
197
}
198     
199     
200     /**
201      *
202      *
203      */

204     public void dropActionChanged(DropTargetDragEvent JavaDoc event) {
205         event.rejectDrag();
206         // Do nothing
207
}
208     
209     public ABEAbstractNode getNBNode(){
210         return null;
211     }
212     
213     public AXIComponent getAXIComponent(){
214         return null;
215     }
216     
217     
218     public abstract void accept(UIVisitor visitor);
219     
220     
221     boolean selected;
222     public void setSelected(boolean selected){
223         if(selected == this.selected)
224             return;
225         firePropertyChange(PROP_SELECTED, this.selected, selected);
226         this.selected = selected;
227     }
228
229     public void removeNotify() {
230         super.removeNotify();
231         firePropertyChange(PROP_COMPONENT_REMOVED, " ", this);
232     }
233     
234     public ABEBaseDropPanel getUIComponentFor(AXIComponent axiComponent){
235         if(getAXIComponent() == axiComponent)
236             return this;
237         return null;
238     }
239     
240     
241     public ABEBaseDropPanel getChildUIComponentFor(AXIComponent axiComponent){
242         return null;
243     }
244     
245     
246     public InstanceUIContext getContext(){
247         return this.context;
248     }
249     
250     ////////////////////////////////////////////////////////////////////////////
251
// Instance members
252
////////////////////////////////////////////////////////////////////////////
253

254     public static final String JavaDoc PROP_ACTIVE="active";
255     public static final String JavaDoc PROP_SELECTED="SELECTED";
256     public static final String JavaDoc PROP_COMPONENT_REMOVED="COMPONENT_REMOVED";
257     
258     
259     
260     
261     ////////////////////////////////////////////////////////////////////////////
262
// Instance members
263
////////////////////////////////////////////////////////////////////////////
264

265     private boolean active;
266 }
267
Popular Tags