public PasteAction(IWorkbenchPart part, GraphicalViewer viewer) { super(part); fGraphicalViewer = viewer; setText(Messages.PasteAction_0); setId(ActionFactory.PASTE.getId()); ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages(); setImageDescriptor(sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); setDisabledImageDescriptor( sharedImages.getImageDescriptor(ISharedImages.IMG_TOOL_PASTE_DISABLED)); setEnabled(false); /** Listen to window activation to udpate Paste Action if clipboard contents has changed */ getWorkbenchPart() .getSite() .getWorkbenchWindow() .getWorkbench() .addWindowListener(windowListener); /** Listen to mouse click position so that the Paste Action can paste objects at that point */ ((GraphicalEditPart) fGraphicalViewer.getRootEditPart()) .getFigure() .addMouseListener(mouseListener); }
@Override public void dispose() { super.dispose(); getWorkbenchPart() .getSite() .getWorkbenchWindow() .getWorkbench() .removeWindowListener(windowListener); ((GraphicalEditPart) fGraphicalViewer.getRootEditPart()) .getFigure() .removeMouseListener(mouseListener); fGraphicalViewer = null; }
private RootModel getRootModel() { GraphicalViewer viewer = (GraphicalViewer) getWorkbenchPart().getAdapter(GraphicalViewer.class); RootModel root = (RootModel) viewer.getRootEditPart().getContents().getModel(); return root; }