### Eclipse Workspace Patch 1.0 #P org.eclipse.gef Index: src/org/eclipse/gef/ui/parts/GraphicalEditor.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/ui/parts/GraphicalEditor.java,v retrieving revision 1.30 diff -u -r1.30 GraphicalEditor.java --- src/org/eclipse/gef/ui/parts/GraphicalEditor.java 19 May 2010 20:27:55 -0000 1.30 +++ src/org/eclipse/gef/ui/parts/GraphicalEditor.java 6 Sep 2010 09:21:36 -0000 @@ -30,6 +30,10 @@ import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.IFigure; +import org.eclipse.draw2d.Viewport; +import org.eclipse.draw2d.geometry.Dimension; +import org.eclipse.draw2d.geometry.Point; +import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gef.ContextMenuProvider; import org.eclipse.gef.DefaultEditDomain; @@ -38,6 +42,7 @@ import org.eclipse.gef.GraphicalViewer; import org.eclipse.gef.commands.CommandStack; import org.eclipse.gef.commands.CommandStackListener; +import org.eclipse.gef.handles.HandleBounds; import org.eclipse.gef.ui.actions.ActionBarContributor; import org.eclipse.gef.ui.actions.ActionRegistry; import org.eclipse.gef.ui.actions.DeleteAction; @@ -59,18 +64,25 @@ * * @author hudsonr */ -public abstract class GraphicalEditor extends EditorPart implements - CommandStackListener, ISelectionListener { - - private static class ActionIDList extends ArrayList { - public boolean add(Object o) { - if (o instanceof IAction) { - try { +public abstract class GraphicalEditor extends EditorPart implements CommandStackListener, + ISelectionListener +{ + + private static class ActionIDList extends ArrayList + { + public boolean add(Object o) + { + if(o instanceof IAction) + { + try + { IAction action = (IAction) o; o = action.getId(); throw new IllegalArgumentException( "Action IDs should be added to lists, not the action: " + action); //$NON-NLS-1$ - } catch (IllegalArgumentException exc) { + } + catch(IllegalArgumentException exc) + { exc.printStackTrace(); } } @@ -79,27 +91,34 @@ } private DefaultEditDomain editDomain; + private GraphicalViewer graphicalViewer; + private ActionRegistry actionRegistry; + private SelectionSynchronizer synchronizer; + private List selectionActions = new ActionIDList(); + private List stackActions = new ActionIDList(); + private List propertyActions = new ActionIDList(); /** * Constructs the editor part */ - public GraphicalEditor() { + public GraphicalEditor() + { } /** * When the command stack changes, the actions interested in the command * stack are updated. * - * @param event - * the change event + * @param event the change event */ - public void commandStackChanged(EventObject event) { + public void commandStackChanged(EventObject event) + { updateActions(stackActions); } @@ -108,16 +127,17 @@ * This is where the root editpart should be configured. Subclasses should * extend or override this method as needed. */ - protected void configureGraphicalViewer() { - getGraphicalViewer().getControl().setBackground( - ColorConstants.listBackground); + protected void configureGraphicalViewer() + { + getGraphicalViewer().getControl().setBackground(ColorConstants.listBackground); } /** * Creates actions for this editor. Subclasses should override this method * to create and register actions with the {@link ActionRegistry}. */ - protected void createActions() { + protected void createActions() + { ActionRegistry registry = getActionRegistry(); IAction action; @@ -146,11 +166,46 @@ /** * Creates the GraphicalViewer on the specified Composite. * - * @param parent - * the parent composite + * @param parent the parent composite */ - protected void createGraphicalViewer(Composite parent) { - GraphicalViewer viewer = new ScrollingGraphicalViewer(); + protected void createGraphicalViewer(Composite parent) + { + GraphicalViewer viewer = new ScrollingGraphicalViewer() + { + public void reveal(EditPart part) + { + super.reveal(part); + Viewport port = getFigureCanvas().getViewport(); + IFigure target = ((GraphicalEditPart) part).getFigure(); + Rectangle exposeRegion = target instanceof HandleBounds ? ((HandleBounds) target) + .getHandleBounds().getCopy() : target.getBounds().getCopy(); + target = target.getParent(); + while(target != null && target != port) + { + target.translateToParent(exposeRegion); + target = target.getParent(); + } + exposeRegion.expand(5, 5); + + Dimension viewportSize = port.getClientArea().getSize(); + + Point topLeft = exposeRegion.getTopLeft(); + Point bottomRight = exposeRegion.getBottomRight().translate( + viewportSize.getNegated()); + Point finalLocation = new Point(); + if(viewportSize.width < exposeRegion.width) finalLocation.x = Math.min( + bottomRight.x, Math.max(topLeft.x, port.getViewLocation().x)); + else finalLocation.x = Math.min(topLeft.x, Math.max(bottomRight.x, port + .getViewLocation().x)); + + if(viewportSize.height < exposeRegion.height) finalLocation.y = Math.min( + bottomRight.y, Math.max(topLeft.y, port.getViewLocation().y)); + else finalLocation.y = Math.min(topLeft.y, Math.max(bottomRight.y, port + .getViewLocation().y)); + + getFigureCanvas().scrollSmoothTo(finalLocation.x, finalLocation.y); + } + }; viewer.createControl(parent); setGraphicalViewer(viewer); configureGraphicalViewer(); @@ -164,20 +219,20 @@ * WARNING: This method may or may not be called by the workbench prior to * {@link #dispose()}. * - * @param parent - * the parent composite + * @param parent the parent composite */ - public void createPartControl(Composite parent) { + public void createPartControl(Composite parent) + { createGraphicalViewer(parent); } /** * @see org.eclipse.ui.IWorkbenchPart#dispose() */ - public void dispose() { + public void dispose() + { getCommandStack().removeCommandStackListener(this); - getSite().getWorkbenchWindow().getSelectionService() - .removeSelectionListener(this); + getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(this); getEditDomain().setActiveTool(null); getActionRegistry().dispose(); super.dispose(); @@ -190,14 +245,16 @@ * * @see org.eclipse.ui.ISaveablePart#doSaveAs() */ - public void doSaveAs() { + public void doSaveAs() + { throw new RuntimeException("doSaveAs must be overridden"); //$NON-NLS-1$ } /** * @see org.eclipse.ui.part.WorkbenchPart#firePropertyChange(int) */ - protected void firePropertyChange(int property) { + protected void firePropertyChange(int property) + { super.firePropertyChange(property); updateActions(propertyActions); } @@ -207,9 +264,9 @@ * * @return the action registry */ - protected ActionRegistry getActionRegistry() { - if (actionRegistry == null) - actionRegistry = new ActionRegistry(); + protected ActionRegistry getActionRegistry() + { + if(actionRegistry == null) actionRegistry = new ActionRegistry(); return actionRegistry; } @@ -223,23 +280,21 @@ * * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) */ - public Object getAdapter(Class type) { - if (type == org.eclipse.ui.views.properties.IPropertySheetPage.class) { + public Object getAdapter(Class type) + { + if(type == org.eclipse.ui.views.properties.IPropertySheetPage.class) + { PropertySheetPage page = new PropertySheetPage(); page.setRootEntry(new UndoablePropertySheetEntry(getCommandStack())); return page; } - if (type == GraphicalViewer.class) - return getGraphicalViewer(); - if (type == CommandStack.class) - return getCommandStack(); - if (type == ActionRegistry.class) - return getActionRegistry(); - if (type == EditPart.class && getGraphicalViewer() != null) - return getGraphicalViewer().getRootEditPart(); - if (type == IFigure.class && getGraphicalViewer() != null) - return ((GraphicalEditPart) getGraphicalViewer().getRootEditPart()) - .getFigure(); + if(type == GraphicalViewer.class) return getGraphicalViewer(); + if(type == CommandStack.class) return getCommandStack(); + if(type == ActionRegistry.class) return getActionRegistry(); + if(type == EditPart.class && getGraphicalViewer() != null) return getGraphicalViewer() + .getRootEditPart(); + if(type == IFigure.class && getGraphicalViewer() != null) return ((GraphicalEditPart) getGraphicalViewer() + .getRootEditPart()).getFigure(); return super.getAdapter(type); } @@ -248,7 +303,8 @@ * * @return the command stack */ - protected CommandStack getCommandStack() { + protected CommandStack getCommandStack() + { return getEditDomain().getCommandStack(); } @@ -257,7 +313,8 @@ * * @return the edit domain */ - protected DefaultEditDomain getEditDomain() { + protected DefaultEditDomain getEditDomain() + { return editDomain; } @@ -266,7 +323,8 @@ * * @return the graphical viewer */ - protected GraphicalViewer getGraphicalViewer() { + protected GraphicalViewer getGraphicalViewer() + { return graphicalViewer; } @@ -278,7 +336,8 @@ * * @return the list of property-dependant actions */ - protected List getPropertyActions() { + protected List getPropertyActions() + { return propertyActions; } @@ -292,7 +351,8 @@ * @see #updateActions(List) * @return the list of selection-dependant action IDs */ - protected List getSelectionActions() { + protected List getSelectionActions() + { return selectionActions; } @@ -302,9 +362,9 @@ * * @return the syncrhonizer */ - protected SelectionSynchronizer getSelectionSynchronizer() { - if (synchronizer == null) - synchronizer = new SelectionSynchronizer(); + protected SelectionSynchronizer getSelectionSynchronizer() + { + if(synchronizer == null) synchronizer = new SelectionSynchronizer(); return synchronizer; } @@ -317,7 +377,8 @@ * * @return the list of stack-dependant action IDs */ - protected List getStackActions() { + protected List getStackActions() + { return stackActions; } @@ -327,7 +388,8 @@ * or more EditPartViewers in sync. The viewer is also registered as the * ISelectionProvider for the Editor's PartSite. */ - protected void hookGraphicalViewer() { + protected void hookGraphicalViewer() + { getSelectionSynchronizer().addViewer(getGraphicalViewer()); getSite().setSelectionProvider(getGraphicalViewer()); } @@ -340,13 +402,12 @@ * * @see org.eclipse.ui.IEditorPart#init(IEditorSite, IEditorInput) */ - public void init(IEditorSite site, IEditorInput input) - throws PartInitException { + public void init(IEditorSite site, IEditorInput input) throws PartInitException + { setSite(site); setInput(input); getCommandStack().addCommandStackListener(this); - getSite().getWorkbenchWindow().getSelectionService() - .addSelectionListener(this); + getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this); initializeActionRegistry(); } @@ -358,7 +419,8 @@ * This method may be called on Editor creation, or lazily the first time * {@link #getActionRegistry()} is called. */ - protected void initializeActionRegistry() { + protected void initializeActionRegistry() + { createActions(); updateActions(propertyActions); updateActions(stackActions); @@ -377,7 +439,8 @@ * * @see org.eclipse.ui.ISaveablePart#isDirty() */ - public boolean isDirty() { + public boolean isDirty() + { return getCommandStack().isDirty(); } @@ -387,7 +450,8 @@ * * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed() */ - public boolean isSaveAsAllowed() { + public boolean isSaveAsAllowed() + { return false; } @@ -395,46 +459,47 @@ * @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, * ISelection) */ - public void selectionChanged(IWorkbenchPart part, ISelection selection) { + public void selectionChanged(IWorkbenchPart part, ISelection selection) + { // If not the active editor, ignore selection changed. - if (this.equals(getSite().getPage().getActiveEditor())) - updateActions(selectionActions); + if(this.equals(getSite().getPage().getActiveEditor())) updateActions(selectionActions); } /** * Sets the ActionRegistry for this EditorPart. * - * @param registry - * the registry + * @param registry the registry */ - protected void setActionRegistry(ActionRegistry registry) { + protected void setActionRegistry(ActionRegistry registry) + { actionRegistry = registry; } /** * Sets the EditDomain for this EditorPart. * - * @param ed - * the domain + * @param ed the domain */ - protected void setEditDomain(DefaultEditDomain ed) { + protected void setEditDomain(DefaultEditDomain ed) + { this.editDomain = ed; } /** * @see org.eclipse.ui.IWorkbenchPart#setFocus() */ - public void setFocus() { + public void setFocus() + { getGraphicalViewer().getControl().setFocus(); } /** * Sets the graphicalViewer for this EditorPart. * - * @param viewer - * the graphical viewer + * @param viewer the graphical viewer */ - protected void setGraphicalViewer(GraphicalViewer viewer) { + protected void setGraphicalViewer(GraphicalViewer viewer) + { getEditDomain().addViewer(viewer); this.graphicalViewer = viewer; } @@ -446,16 +511,16 @@ * is an {@link UpdateAction}, it will have its update() method * called. * - * @param actionIds - * the list of IDs to update + * @param actionIds the list of IDs to update */ - protected void updateActions(List actionIds) { + protected void updateActions(List actionIds) + { ActionRegistry registry = getActionRegistry(); Iterator iter = actionIds.iterator(); - while (iter.hasNext()) { + while(iter.hasNext()) + { IAction action = registry.getAction(iter.next()); - if (action instanceof UpdateAction) - ((UpdateAction) action).update(); + if(action instanceof UpdateAction) ((UpdateAction) action).update(); } } Index: src/org/eclipse/gef/ui/parts/ScrollingGraphicalViewer.java =================================================================== RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.gef/src/org/eclipse/gef/ui/parts/ScrollingGraphicalViewer.java,v retrieving revision 1.15 diff -u -r1.15 ScrollingGraphicalViewer.java --- src/org/eclipse/gef/ui/parts/ScrollingGraphicalViewer.java 19 May 2010 20:27:55 -0000 1.15 +++ src/org/eclipse/gef/ui/parts/ScrollingGraphicalViewer.java 6 Sep 2010 09:21:36 -0000 @@ -22,6 +22,7 @@ import org.eclipse.gef.EditPart; import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.handles.HandleBounds; /** * A Graphical Viewer implementation which uses a @@ -88,7 +89,9 @@ super.reveal(part); Viewport port = getFigureCanvas().getViewport(); IFigure target = ((GraphicalEditPart) part).getFigure(); - Rectangle exposeRegion = target.getBounds().getCopy(); + Rectangle exposeRegion = target instanceof HandleBounds ? + ((HandleBounds) target).getHandleBounds().getCopy() : + target.getBounds().getCopy(); target = target.getParent(); while (target != null && target != port) { target.translateToParent(exposeRegion);