KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > edit > tree > DrawComponentContainerTreeEditPart


1 /* *****************************************************************************
2  * NightLabs Editor2D - Graphical editor framework *
3  * Copyright (C) 2004-2005 NightLabs - http://NightLabs.org *
4  * Project author: Daniel Mazurek <Daniel.Mazurek [at] nightlabs [dot] org> *
5  * *
6  * This library is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin St, Fifth Floor, *
20  * Boston, MA 02110-1301 USA *
21  * *
22  * Or get it online : *
23  * http://www.gnu.org/copyleft/lesser.html *
24  * *
25  * *
26  ******************************************************************************/

27
28 package org.nightlabs.editor2d.edit.tree;
29
30 import java.beans.PropertyChangeEvent JavaDoc;
31 import java.util.List JavaDoc;
32
33 import org.eclipse.gef.EditPolicy;
34 import org.eclipse.gef.RootEditPart;
35 import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
36
37 import org.nightlabs.editor2d.DrawComponentContainer;
38 import org.nightlabs.editor2d.editpolicy.DrawComponentContainerEditPolicy;
39 import org.nightlabs.editor2d.editpolicy.tree.DrawComponentTreeContainerEditPolicy;
40
41 public abstract class DrawComponentContainerTreeEditPart
42 extends DrawComponentTreeEditPart
43 {
44   /**
45    * Constructor initializes this with the given model.
46    *
47    * @param model Model for this.
48    */

49   public DrawComponentContainerTreeEditPart(DrawComponentContainer model) {
50     super(model);
51   }
52     
53   /**
54    * Creates and installs pertinent EditPolicies.
55    */

56   protected void createEditPolicies()
57   {
58     super.createEditPolicies();
59     installEditPolicy(EditPolicy.CONTAINER_ROLE, new DrawComponentContainerEditPolicy());
60     installEditPolicy(EditPolicy.TREE_CONTAINER_ROLE, new DrawComponentTreeContainerEditPolicy());
61     //If this editpart is the contents of the viewer, then it is not deletable!
62
if (getParent() instanceof RootEditPart)
63         installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());
64   }
65
66   /**
67    * Returns the model of this as a LogicDiagram.
68    *
69    * @return Model of this.
70    */

71   protected DrawComponentContainer getDrawComponentContainer() {
72     return (DrawComponentContainer)getModel();
73   }
74
75   /**
76    * Returns the children of this from the model,
77    * as this is capable enough of holding EditParts.
78    *
79    * @return List of children.
80    */

81   protected List JavaDoc getModelChildren()
82   {
83     return getDrawComponentContainer().getDrawComponents();
84   }
85   
86     protected void propertyChanged(PropertyChangeEvent JavaDoc evt)
87     {
88         super.propertyChanged(evt);
89         String JavaDoc propertyName = evt.getPropertyName();
90         if (propertyName.equals(DrawComponentContainer.CHILD_ADDED)) {
91             LOGGER.debug(propertyName);
92             refreshChildren();
93         }
94         else if (propertyName.equals(DrawComponentContainer.CHILD_REMOVED)) {
95             LOGGER.debug(propertyName);
96             refreshChildren();
97         }
98     }
99   
100 // /**
101
// * Returns the children of this from the model,
102
// * as this is capable enough of holding EditParts.
103
// *
104
// * @return List of children.
105
// */
106
// protected List getModelChildren()
107
// {
108
// if (!getFilterMan().isAllFilterSet()) {
109
// List filterChildren = new ArrayList();
110
// for (Iterator itFilter = getFilterMan().getFilters().iterator(); itFilter.hasNext(); ) {
111
// Class filter = (Class) itFilter.next();
112
// for (Iterator it = getDrawComponentContainer().getDrawComponents().iterator(); it.hasNext(); ) {
113
// DrawComponent dc = (DrawComponent) it.next();
114
// if (filter.isAssignableFrom(dc.getClass())) {
115
// filterChildren.add(dc);
116
// }
117
// }
118
// }
119
// return filterChildren;
120
// }
121
// else {
122
// return getDrawComponentContainer().getDrawComponents();
123
// }
124
// }
125

126 }
127
Popular Tags