1 27 28 package org.nightlabs.editor2d.actions; 29 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.Iterator ; 33 import java.util.List ; 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 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 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 name = dc.getName(); 66 Class c = dc.getClass(); 67 List 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 getDrawComponentsWithSameName(Collection drawComponents, String name) 76 { 77 List drawComponentsWithSameName = new ArrayList (); 78 for (Iterator it = drawComponents.iterator(); it.hasNext(); ) 79 { 80 DrawComponent dc = (DrawComponent) it.next(); 81 String 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 |