KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nightlabs > editor2d > actions > SelectAllWithSameName


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.actions;
29
30 import java.util.ArrayList JavaDoc;
31 import java.util.Collection JavaDoc;
32 import java.util.Iterator JavaDoc;
33 import java.util.List JavaDoc;
34
35 import org.eclipse.gef.EditPart;
36
37 import org.nightlabs.editor2d.AbstractEditor;
38 import org.nightlabs.editor2d.DrawComponent;
39 import org.nightlabs.editor2d.EditorPlugin;
40
41 public class SelectAllWithSameName
42 extends AbstractEditorSelectionAction
43 {
44     public static final String JavaDoc ID = SelectAllWithSameName.class.getName();
45     
46     public SelectAllWithSameName(AbstractEditor editor, int style)
47     {
48         super(editor, style);
49     }
50
51     public SelectAllWithSameName(AbstractEditor editor)
52     {
53         super(editor);
54     }
55
56     protected EditPart editPart = null;
57     protected List JavaDoc drawComponentsWithSameName = null;
58     
59     protected boolean calculateEnabled()
60     {
61         if (getSelectedObjects().size() == 1)
62         {
63             editPart = (EditPart) getSelectedObjects().get(0);
64             DrawComponent dc = (DrawComponent) editPart.getModel();
65             String JavaDoc name = dc.getName();
66             Class JavaDoc c = dc.getClass();
67             List JavaDoc drawComponents = getMultiLayerDrawComponent().getDrawComponents(c);
68             drawComponentsWithSameName = getDrawComponentsWithSameName(drawComponents, name);
69             if (!drawComponentsWithSameName.isEmpty())
70                 return true;
71         }
72         return false;
73     }
74
75     public List JavaDoc getDrawComponentsWithSameName(Collection JavaDoc drawComponents, String JavaDoc name)
76     {
77         List JavaDoc drawComponentsWithSameName = new ArrayList JavaDoc();
78         for (Iterator JavaDoc it = drawComponents.iterator(); it.hasNext(); )
79         {
80             DrawComponent dc = (DrawComponent) it.next();
81             String JavaDoc dcName = dc.getName();
82             if (dcName.equals(name))
83                 drawComponentsWithSameName.add(dc);
84         }
85         return drawComponentsWithSameName;
86     }
87
88     public void run()
89     {
90         selectEditPart(drawComponentsWithSameName);
91     }
92
93     protected void init()
94     {
95         setId(ID);
96         setText(EditorPlugin.getResourceString("action.selectAllWithSameName.text"));
97         setToolTipText(EditorPlugin.getResourceString("action.selectAllWithSameName.tooltip"));
98     }
99         
100 }
101
Popular Tags