KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
31 import java.util.Iterator JavaDoc;
32 import java.util.List JavaDoc;
33
34 import org.eclipse.gef.EditPolicy;
35 import org.eclipse.gef.editpolicies.RootComponentEditPolicy;
36 import org.eclipse.jface.resource.ImageDescriptor;
37 import org.eclipse.swt.graphics.Image;
38 import org.eclipse.ui.views.properties.IPropertySource;
39
40 import org.nightlabs.editor2d.DrawComponent;
41 import org.nightlabs.editor2d.EditorPlugin;
42 import org.nightlabs.editor2d.Layer;
43 import org.nightlabs.editor2d.MultiLayerDrawComponent;
44 import org.nightlabs.editor2d.editpolicy.DrawComponentContainerEditPolicy;
45 import org.nightlabs.editor2d.editpolicy.tree.MultiLayerDrawComponentTreeEditPolicy;
46 import org.nightlabs.editor2d.model.MultiLayerDrawComponentPropertySource;
47 import org.nightlabs.editor2d.outline.filter.FilterManager;
48
49
50 public class MultiLayerDrawComponentTreeEditPart
51 extends DrawComponentContainerTreeEditPart
52 {
53 // public static Image SUN_ICON = ImageDescriptor.createFromFile(EditorPlugin.class, "icons/sun16.gif").createImage();
54

55   /**
56    * @param model
57    */

58   public MultiLayerDrawComponentTreeEditPart(MultiLayerDrawComponent model, FilterManager filterMan) {
59     super(model);
60     this.filterMan = filterMan;
61   }
62 // public MultiLayerDrawComponentTreeEditPart(MultiLayerDrawComponent model) {
63
// super(model);
64
// }
65

66   protected FilterManager filterMan;
67   public FilterManager getFilterMan() {
68     return filterMan;
69   }
70   
71   public MultiLayerDrawComponent getMultiLayerDrawComponent() {
72     return (MultiLayerDrawComponent) getModel();
73   }
74   
75   /* (non-Javadoc)
76    * @see org.nightlabs.editor2d.edit.tree.DrawComponentTreeEditPart#getIcon()
77    */

78   public Image getImage() {
79     return null;
80   }
81
82   /**
83    * Creates and installs pertinent EditPolicies.
84    */

85   protected void createEditPolicies()
86   {
87     super.createEditPolicies();
88     installEditPolicy(EditPolicy.CONTAINER_ROLE, new DrawComponentContainerEditPolicy());
89     installEditPolicy(EditPolicy.TREE_CONTAINER_ROLE, new MultiLayerDrawComponentTreeEditPolicy());
90     //If this editpart is the contents of the viewer, then it is not deletable!
91
installEditPolicy(EditPolicy.COMPONENT_ROLE, new RootComponentEditPolicy());
92   }
93   
94   protected List JavaDoc getModelChildren()
95   {
96     if (getFilterMan().isAllFilterSet()) {
97         return getMultiLayerDrawComponent().getDrawComponents();
98     }
99     else {
100       List JavaDoc filterChildren = new ArrayList JavaDoc();
101         for (Iterator JavaDoc itFilter = getFilterMan().getFilters().iterator(); itFilter.hasNext(); ) {
102             Class JavaDoc filter = (Class JavaDoc) itFilter.next();
103         for (Iterator JavaDoc itLayers = getDrawComponentContainer().getDrawComponents().iterator(); itLayers.hasNext(); ) {
104           Layer l = (Layer) itLayers.next();
105           for (Iterator JavaDoc itDrawOrder = l.getDrawComponents().iterator(); itDrawOrder.hasNext(); ) {
106             DrawComponent dc = (DrawComponent) itDrawOrder.next();
107                 if (filter.isAssignableFrom(dc.getClass())) {
108                     filterChildren.add(dc);
109                 }
110           }
111         }
112         }
113       return filterChildren;
114     }
115   }
116   
117   protected IPropertySource getPropertySource()
118   {
119     if (propertySource == null)
120     {
121       propertySource =
122         new MultiLayerDrawComponentPropertySource(getMultiLayerDrawComponent());
123     }
124     return propertySource;
125   }
126 }
127
Popular Tags