1 19 20 21 package ca.mcgill.sable.graph; 22 23 import org.eclipse.core.resources.IMarker; 24 import org.eclipse.core.runtime.IProgressMonitor; 25 import org.eclipse.ui.*; 26 import org.eclipse.gef.ui.parts.*; 27 import org.eclipse.gef.*; 28 import org.eclipse.gef.editparts.*; 29 import ca.mcgill.sable.graph.model.*; 30 import ca.mcgill.sable.graph.editparts.*; 31 32 import org.eclipse.gef.palette.*; 33 import org.eclipse.jface.action.*; 34 import org.eclipse.gef.ui.actions.*; 35 import ca.mcgill.sable.graph.actions.*; 36 37 import java.util.*; 38 39 40 public class GraphEditor extends GraphicalEditor { 41 42 private Graph graph; 43 44 47 public GraphEditor() { 48 DefaultEditDomain defaultEditDomain = new DefaultEditDomain(this); 49 setEditDomain(defaultEditDomain); 50 } 51 52 55 protected void initializeGraphicalViewer() { 56 getGraphicalViewer().setContents(graph); 57 } 58 59 protected void configureGraphicalViewer() { 60 super.configureGraphicalViewer(); 61 ScalableRootEditPart root = new ScalableRootEditPart(); 62 getGraphicalViewer().setRootEditPart(root); 63 64 ZoomManager zManager = root.getZoomManager(); 65 double [] zoomLevels = new double[10]; 66 for (int i = 0; i < zoomLevels.length; i++){ 67 zoomLevels[i] = (i + 1) * 0.25; 68 } 69 zManager.setZoomLevels(zoomLevels); 70 IAction zoomIn = new ZoomInAction(zManager); 71 IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager()); 72 73 getActionRegistry().registerAction(zoomIn); 74 getActionRegistry().registerAction(zoomOut); 75 76 IAction printAction = new PrintAction(this); 77 getActionRegistry().registerAction(printAction); 78 79 getSite().getKeyBindingService().registerAction(zoomIn); 80 getSite().getKeyBindingService().registerAction(zoomOut); 81 82 getGraphicalViewer().setEditPartFactory(new PartFactory()); 83 getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer())); 84 85 } 86 87 public void setMenuProvider(ContextMenuProvider prov){ 88 getGraphicalViewer().setContextMenu(prov); 89 getSite().registerContextMenu(prov, getGraphicalViewer()); 90 } 91 92 public void setPartFactory(PartFactory factory){ 93 getGraphicalViewer().setEditPartFactory(factory); 94 } 95 96 protected void setInput(IEditorInput input){ 97 super.setInput(input); 98 if (input instanceof Graph){ 99 setGraph((Graph)input); 100 } 101 } 102 103 106 public void doSave(IProgressMonitor monitor) { 107 } 108 109 112 public void doSaveAs() { 113 } 114 115 118 public void gotoMarker(IMarker marker) { 119 } 120 121 124 public boolean isDirty() { 125 return false; 126 } 127 128 131 public boolean isSaveAsAllowed() { 132 return false; 133 } 134 135 138 public Graph getGraph() { 139 return graph; 140 } 141 142 145 public void setGraph(Graph g) { 146 graph = g; 147 } 148 149 public void setTitle(String name){ 150 super.setTitle(name); 151 } 152 153 public void setTitleTooltip(String text){ 154 super.setTitleToolTip(text); 155 } 156 157 public void createActions(){ 158 super.createActions(); 159 ActionRegistry registry = getActionRegistry(); 160 IAction action = new SimpleSelectAction(this); 161 registry.registerAction(action); 162 getSelectionActions().add(action.getId()); 163 } 164 165 public ActionRegistry getGraphEditorActionRegistry(){ 166 return getActionRegistry(); 167 } 168 169 public GraphicalViewer getGraphEditorGraphicalViewer(){ 170 return getGraphicalViewer(); 171 } 172 173 public List getGraphEditorSelectionActions(){ 174 return getSelectionActions(); 175 } 176 177 178 public String getToolTipText(){ 179 return getTitle(); 180 } 181 182 public String getTitleToolTip(){ 183 return super.getTitleToolTip(); 184 } 185 186 187 } 188 | Popular Tags |