1 27 28 package org.nightlabs.editor2d.actions; 29 30 import java.util.ArrayList ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 34 import org.eclipse.gef.EditPart; 35 import org.eclipse.gef.GraphicalViewer; 36 import org.eclipse.gef.ui.actions.EditorPartAction; 37 import org.eclipse.jface.viewers.StructuredSelection; 38 import org.eclipse.swt.widgets.Shell; 39 40 import org.nightlabs.editor2d.AbstractEditor; 41 import org.nightlabs.editor2d.DrawComponent; 42 import org.nightlabs.editor2d.Layer; 43 import org.nightlabs.editor2d.MultiLayerDrawComponent; 44 45 public abstract class AbstractEditorAction 46 extends EditorPartAction 47 { 48 public AbstractEditorAction(AbstractEditor editor, int style) { 49 super(editor, style); 50 } 51 52 public AbstractEditorAction(AbstractEditor editor) { 53 super(editor); 54 } 55 56 protected abstract boolean calculateEnabled(); 57 58 63 public AbstractEditor getEditor() { 64 return (AbstractEditor) getWorkbenchPart(); 65 } 66 67 72 public MultiLayerDrawComponent getMultiLayerDrawComponent() { 73 return getEditor().getMultiLayerDrawComponent(); 74 } 75 76 80 public Layer getCurrentLayer() { 81 return getMultiLayerDrawComponent().getCurrentLayer(); 82 } 83 84 89 public GraphicalViewer getGraphicalViewer() { 90 return getEditor().getOutlineGraphicalViewer(); 91 } 92 93 99 public EditPart getEditPart(DrawComponent model) { 100 return (EditPart) getGraphicalViewer().getEditPartRegistry().get(model); 101 } 102 103 108 public List getEditParts(List drawComponents) 109 { 110 List editParts = new ArrayList (); 111 for (Iterator it = drawComponents.iterator(); it.hasNext(); ) 112 { 113 DrawComponent dc = (DrawComponent) it.next(); 114 EditPart ep = getEditPart(dc); 115 editParts.add(ep); 116 } 117 return editParts; 118 } 119 120 125 public void selectEditPart(List drawComponents) 126 { 127 List editParts = getEditParts(drawComponents); 128 getGraphicalViewer().setSelection(new StructuredSelection(editParts)); 129 } 130 131 135 public Shell getShell() { 136 return getEditor().getSite().getShell(); 137 } 138 139 142 public boolean isActiveEditor() 143 { 144 if (getWorkbenchPart().getSite().getWorkbenchWindow().getActivePage() != null) 146 { 147 if (getWorkbenchPart().getSite().getWorkbenchWindow().getActivePage().getActiveEditor().equals(getEditor())) { 148 return true; 149 } 150 } 151 return false; 152 } 153 } 154 | Popular Tags |