KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.gef.ui.actions.SelectionAction;
31 import org.eclipse.ui.IWorkbenchPart;
32
33 import org.nightlabs.editor2d.EditorPlugin;
34 import org.nightlabs.editor2d.EditorStateManager;
35 import org.nightlabs.editor2d.edit.ShapeDrawComponentEditPart;
36 import org.nightlabs.editor2d.request.EditorRequestConstants;
37
38
39 public class EditShapeAction
40 extends SelectionAction
41 implements EditorRequestConstants
42 {
43   public static final String JavaDoc ID = EditShapeAction.class.getName();
44   
45   /**
46    * @param part
47    */

48   public EditShapeAction(IWorkbenchPart part) {
49     super(part);
50   }
51
52   /**
53    * returns <code>true</code> if there is exactly 1 EditPart selected that understand
54    * a request of type: {@link EditorRequestConstants#REQ_EDIT_SHAPE}.
55    * @return <code>true</code> if enabled
56    */

57   protected boolean calculateEnabled()
58   {
59     if (EditorStateManager.getCurrentState() != EditorStateManager.STATE_EDIT_SHAPE)
60     {
61         if (getSelectedObjects().size() == 1 && (getSelectedObjects().get(0) instanceof ShapeDrawComponentEditPart)) {
62         return true;
63         }
64     }
65     return false;
66   }
67   
68   /**
69    * @see org.eclipse.gef.ui.actions.WorkbenchPartAction#init()
70    */

71   protected void init()
72   {
73     super.init();
74     setText(EditorPlugin.getResourceString("action.editshape.text"));
75     setToolTipText(EditorPlugin.getResourceString("action.editshape.tooltip"));
76     setId(ID);
77 // setImageDescriptor(ImageDescriptor.createFromFile(EditorPlugin.class,"icons/editShape16.gif"));
78
}
79   
80   /**
81    * @see org.eclipse.jface.action.IAction#run()
82    */

83   public void run()
84   {
85 // EditorStateManager.setCurrentState(EditorStateManager.STATE_EDIT_SHAPE);
86
if (getSelectedObjects().size() == 1 && (getSelectedObjects().get(0) instanceof ShapeDrawComponentEditPart))
87     {
88         ShapeDrawComponentEditPart sdcEP = (ShapeDrawComponentEditPart) getSelectedObjects().get(0);
89       EditorStateManager.setEditShapeMode(sdcEP);
90     }
91   }
92     
93 }
94
Popular Tags