private void refreshGraphicalViewer() { IEditorInput input = getEditorInput(); if (input instanceof IFileEditorInput) { try { IFile file = ((IFileEditorInput) input).getFile(); GraphicalViewer viewer = getGraphicalViewer(); // desirialize RootModel newRoot = null; try { newRoot = DiagramSerializer.deserialize(file.getContents()); } catch (Exception ex) { UMLPlugin.logException(ex); return; } // copy to editing model RootModel root = (RootModel) viewer.getContents().getModel(); root.copyFrom(newRoot); } catch (Exception ex) { UMLPlugin.logException(ex); } } }
/** * コネクション用のPaletteEntryを作成します。 * * @param itemName パレットに表示するアイテム名 * @param clazz モデルのクラス * @param icon パレットに表示するアイコンのパス * @return PaletteEntry */ protected PaletteEntry createConnectionEntry(String itemName, Class<?> clazz, String icon) { ConnectionCreationToolEntry entry = new ConnectionCreationToolEntry( itemName, itemName, new SimpleFactory(clazz), UMLPlugin.getImageDescriptor(icon), UMLPlugin.getImageDescriptor(icon)); return entry; }
public DiagramEditor() { super(); setEditDomain(new DefaultEditDomain(this)); getActionRegistry().registerAction(new UndoRetargetAction()); getActionRegistry().registerAction(new RedoRetargetAction()); getActionRegistry().registerAction(new DeleteRetargetAction()); UMLPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); ResourcesPlugin.getWorkspace().addResourceChangeListener(this); }
protected void initializeGraphicalViewer() { GraphicalViewer viewer = getGraphicalViewer(); IFile file = ((IFileEditorInput) getEditorInput()).getFile(); RootModel root = null; if (file.exists()) { try { root = DiagramSerializer.deserialize(file.getContents()); validateModel(root); } catch (Exception ex) { UMLPlugin.logException(ex); } } if (root == null) { root = createInitializeModel(); } viewer.setContents(root); addDndSupport(viewer, getDiagramType()); applyPreferences(); }
protected void applyPreferences() { IPreferenceStore store = UMLPlugin.getDefault().getPreferenceStore(); getGraphicalViewer() .setProperty( SnapToGrid.PROPERTY_GRID_ENABLED, new Boolean(store.getBoolean(UMLPlugin.PREF_SHOW_GRID))); getGraphicalViewer() .setProperty( SnapToGrid.PROPERTY_GRID_VISIBLE, new Boolean(store.getBoolean(UMLPlugin.PREF_SHOW_GRID))); int gridSize = store.getInt(UMLPlugin.PREF_GRID_SIZE); getGraphicalViewer() .setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(gridSize, gridSize)); getGraphicalViewer() .setProperty( SnapToGeometry.PROPERTY_SNAP_ENABLED, new Boolean(store.getBoolean(UMLPlugin.PREF_SNAP_GEOMETRY))); }
public void dispose() { UMLPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); super.dispose(); }
protected void configureGraphicalViewer() { super.configureGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer(); viewer.setEditPartFactory(createEditPartFactory()); ScalableRootEditPart rootEditPart = new ScalableRootEditPart(); viewer.setRootEditPart(rootEditPart); // ZoomManagerの取得 ZoomManager manager = rootEditPart.getZoomManager(); // ズームレベルの設定 double[] zoomLevels = new double[] {0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0}; manager.setZoomLevels(zoomLevels); // ズーム レベル コントリビューションの設定 ArrayList<String> zoomContributions = new ArrayList<String>(); zoomContributions.add(ZoomManager.FIT_ALL); zoomContributions.add(ZoomManager.FIT_HEIGHT); zoomContributions.add(ZoomManager.FIT_WIDTH); manager.setZoomLevelContributions(zoomContributions); // 拡大アクションの作成と登録 getActionRegistry().registerAction(new ZoomInAction(manager)); // 縮小アクションの作成と登録 getActionRegistry().registerAction(new ZoomOutAction(manager)); getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer())); // コンテクストメニューの作成 String menuId = this.getClass().getName() + ".EditorContext"; MenuManager menuMgr = new MenuManager(menuId, menuId); openPropertyAction = new OpenPropertyViewAction(viewer); openOutlineAction = new OpenOutlineViewAction(viewer); saveAsImageAction = new SaveAsImageAction(viewer); copyAsImageAction = new CopyAsImageAction(viewer); createDiagramAction(viewer); getSite().registerContextMenu(menuId, menuMgr, viewer); PrintAction printAction = new PrintAction(this); printAction.setImageDescriptor(UMLPlugin.getImageDescriptor("icons/print.gif")); getActionRegistry().registerAction(printAction); final DeleteAction deleteAction = new DeleteAction((IWorkbenchPart) this); deleteAction.setSelectionProvider(getGraphicalViewer()); getActionRegistry().registerAction(deleteAction); viewer.addSelectionChangedListener( new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { deleteAction.update(); } }); // Actions // IAction showRulers = new ToggleRulerVisibilityAction(getGraphicalViewer()); // getActionRegistry().registerAction(showRulers); // // IAction snapAction = new ToggleSnapToGeometryAction(getGraphicalViewer()); // getActionRegistry().registerAction(snapAction); // // IAction showGrid = new ToggleGridAction(getGraphicalViewer()); // getActionRegistry().registerAction(showGrid); menuMgr.add(new Separator("edit")); menuMgr.add(getActionRegistry().getAction(ActionFactory.DELETE.getId())); menuMgr.add(getActionRegistry().getAction(ActionFactory.UNDO.getId())); menuMgr.add(getActionRegistry().getAction(ActionFactory.REDO.getId())); // menuMgr.add(getActionRegistry().getAction(ActionFactory.COPY.getId())); // menuMgr.add(getActionRegistry().getAction(ActionFactory.PASTE.getId())); menuMgr.add(new Separator("zoom")); menuMgr.add(getActionRegistry().getAction(GEFActionConstants.ZOOM_IN)); menuMgr.add(getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT)); fillDiagramPopupMenu(menuMgr); menuMgr.add(new Separator("print")); menuMgr.add(saveAsImageAction); menuMgr.add(copyAsImageAction); menuMgr.add(printAction); menuMgr.add(new Separator("views")); menuMgr.add(openPropertyAction); menuMgr.add(openOutlineAction); menuMgr.add(new Separator("generate")); menuMgr.add(new Separator("additions")); viewer.setContextMenu(menuMgr); viewer.setKeyHandler(new GraphicalViewerKeyHandler(viewer).setParent(getCommonKeyHandler())); }