### Eclipse Workspace Patch 1.0 #P org.eclipse.gmf.runtime.diagram.ui.properties Index: src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.properties =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.properties/src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.properties,v retrieving revision 1.4 diff -u -r1.4 DiagramUIPropertiesMessages.properties --- src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.properties 6 Apr 2006 20:30:22 -0000 1.4 +++ src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.properties 7 Dec 2007 16:10:09 -0000 @@ -1,6 +1,6 @@ # ============================================================================== #*+------------------------------------------------------------------------+ -#*| Copyright (c) 2005 IBM Corporation and others. | +#*| Copyright (c) 2005, 2007 IBM Corporation and others. | #*| All rights reserved. This program and the accompanying materials | #*| are made available under the terms of the Eclipse Public License v1.0 | #*| which accompanies this distribution, and is available at | @@ -57,6 +57,7 @@ Grid_On_Label_Text=Show Grid Grid_Level_Label_Text=Grid In Front Snap_To_Grid_Label_Text=Snap To Grid +Snap_To_Geometry_Label_Text=Snap To Geometry Grid_Spacing_Label_Text=Grid Spacing Ruler_On_Label_Text=Show Ruler Ruler_Units_Label_Text=Ruler Units Index: src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.properties/src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.java,v retrieving revision 1.5 diff -u -r1.5 DiagramUIPropertiesMessages.java --- src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.java 3 Oct 2006 15:02:59 -0000 1.5 +++ src/org/eclipse/gmf/runtime/diagram/ui/properties/internal/l10n/DiagramUIPropertiesMessages.java 7 Dec 2007 16:10:09 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -56,6 +56,7 @@ public static String Grid_On_Label_Text; public static String Grid_Level_Label_Text; public static String Snap_To_Grid_Label_Text; + public static String Snap_To_Geometry_Label_Text; public static String Grid_Spacing_Label_Text; public static String Ruler_On_Label_Text; public static String Ruler_Units_Label_Text; Index: src/org/eclipse/gmf/runtime/diagram/ui/properties/sections/grid/RulerGridPropertySection.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui.properties/src/org/eclipse/gmf/runtime/diagram/ui/properties/sections/grid/RulerGridPropertySection.java,v retrieving revision 1.11 diff -u -r1.11 RulerGridPropertySection.java --- src/org/eclipse/gmf/runtime/diagram/ui/properties/sections/grid/RulerGridPropertySection.java 6 Nov 2007 13:59:49 -0000 1.11 +++ src/org/eclipse/gmf/runtime/diagram/ui/properties/sections/grid/RulerGridPropertySection.java 7 Dec 2007 16:10:09 -0000 @@ -53,6 +53,8 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Text; +import org.eclipse.swt.widgets.ToolBar; +import org.eclipse.swt.widgets.ToolItem; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; @@ -71,16 +73,18 @@ private Button gridVisibilityButton; private Button gridOrderButton; private Button snapToGridButton; + private Button snapToGeometryButton; private Button restoreButton; private Button rulerVisibilityButton; - private Button lineColorButton; + private ToolItem lineColorButton; // Labels private static final String GRID_ON_LABEL = DiagramUIPropertiesMessages.Grid_On_Label_Text; private static final String GRID_LEVEL_LABEL = DiagramUIPropertiesMessages.Grid_Level_Label_Text; private static final String SNAP_TO_GRID_LABEL = DiagramUIPropertiesMessages.Snap_To_Grid_Label_Text; + private static final String SNAP_TO_GEOMETRY_LABEL = DiagramUIPropertiesMessages.Snap_To_Geometry_Label_Text; private static final String RULER_ON_LABEL = DiagramUIPropertiesMessages.Ruler_On_Label_Text; private static final String RULER_UNITS_LABEL = DiagramUIPropertiesMessages.Ruler_Units_Label_Text; private static final String GRID_SPACING_LABEL = DiagramUIPropertiesMessages.Grid_Spacing_Label_Text; @@ -230,7 +234,18 @@ setWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGRID, snapToGridButton.getSelection()); } }); + + // Create snap to geometry checkbox + snapToGeometryButton = getWidgetFactory().createButton( + extraComposite, SNAP_TO_GEOMETRY_LABEL, SWT.CHECK); + snapToGeometryButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + // Set the snap to geometry workspace property + setWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGEOMETRY, snapToGeometryButton.getSelection()); + } + }); + // Create restore to preferences defaults restoreButton = getWidgetFactory().createButton( extraComposite, RESTORE_LABEL, SWT.PUSH); @@ -244,7 +259,7 @@ IPreferenceStore preferenceStore = getPreferenceStore(); // The workspace properties will always exist because it is set - // + IPreferenceStore wsPrefStore = getWorkspaceViewerProperties(); if (wsPrefStore.getBoolean(WorkspaceViewerProperties.GRIDORDER) == false) { @@ -265,7 +280,9 @@ if (wsPrefStore.getBoolean(WorkspaceViewerProperties.SNAPTOGRID) != preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GRID)) { wsPrefStore.setValue(WorkspaceViewerProperties.SNAPTOGRID, preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GRID)); } - + if (wsPrefStore.getBoolean(WorkspaceViewerProperties.SNAPTOGEOMETRY) != preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GEOMETRY)) { + wsPrefStore.setValue(WorkspaceViewerProperties.SNAPTOGEOMETRY, preferenceStore.getBoolean(IPreferenceConstants.PREF_SNAP_TO_GEOMETRY)); + } if ((wsPrefStore.getInt(WorkspaceViewerProperties.RULERUNIT) != preferenceStore.getInt(IPreferenceConstants.PREF_RULER_UNITS)) || (wsPrefStore.getDouble(WorkspaceViewerProperties.GRIDSPACING) != preferenceStore.getDouble(IPreferenceConstants.PREF_GRID_SPACING))) { wsPrefStore.setValue(WorkspaceViewerProperties.RULERUNIT, preferenceStore.getInt(IPreferenceConstants.PREF_RULER_UNITS)); @@ -286,16 +303,11 @@ private void createLineColorControl(Composite composite) { getWidgetFactory().createLabel(composite, LINE_COLOR_LABEL); - - lineColorButton = new Button(composite, SWT.PUSH); + ToolBar toolBar = new ToolBar(composite, SWT.FLAT); + toolBar.setLayout(new GridLayout(1, false)); + toolBar.setBackground(composite.getBackground()); + lineColorButton = new ToolItem(toolBar, SWT.DROP_DOWN); lineColorButton.setImage(DiagramUIPropertiesImages.get(DiagramUIPropertiesImages.IMG_LINE_COLOR)); - - lineColorButton.getAccessible().addAccessibleListener(new AccessibleAdapter() { - public void getName(AccessibleEvent e) { - e.result = DiagramUIMessages.PropertyDescriptorFactory_LineColor; - } - }); - lineColorButton.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent event) { @@ -316,6 +328,15 @@ } }); lineColorButton.setEnabled(true); + + //the accessibility listener is applied to the whole tool bar because there is only one item in it, in the event + //that additional tool items are added, this should be changed to search for the tool bar's children and their + //their respective tool tips. Refer to ColorsAndFontsPropertySection.java. + toolBar.getAccessible().addAccessibleListener(new AccessibleAdapter() { + public void getName(AccessibleEvent e) { + e.result = DiagramUIMessages.PropertyDescriptorFactory_LineColor; + } + }); } private void createLineStyleControl(Composite composite) { @@ -341,30 +362,30 @@ /** * @param event - * selection event - * @param button - + * @param toolItem - * event source * @param imageDescriptor - * the image to draw overlay on the button after the new * color is set * @return - new RGB color, or null if none selected */ - private RGB changeColor(SelectionEvent event, Button button, + private RGB changeColor(SelectionEvent event, ToolItem toolItem, ImageDescriptor imageDescriptor, int previousColor) { - ColorPalettePopup popup = new ColorPalettePopup(button.getParent() + ColorPalettePopup popup = new ColorPalettePopup(toolItem.getParent() .getShell(), IDialogConstants.BUTTON_BAR_HEIGHT); popup.setPreviousColor(previousColor); - Rectangle r = button.getBounds(); - Point location = button.getParent().toDisplay(r.x, r.y); + Rectangle r = toolItem.getBounds(); + Point location = toolItem.getParent().toDisplay(r.x, r.y); popup.open(new Point(location.x, location.y + r.height)); if (popup.useDefaultColor()) { Image overlyedImage = new ColorOverlayImageDescriptor( imageDescriptor.getImageData(), FigureUtilities.integerToRGB(new Integer(LIGHT_GRAY_RGB))) .createImage(); - disposeImage(button.getImage()); - button.setImage(overlyedImage); + disposeImage(toolItem.getImage()); + toolItem.setImage(overlyedImage); return FigureUtilities.integerToRGB(new Integer(LIGHT_GRAY_RGB)); } @@ -372,8 +393,8 @@ Image overlyedImage = new ColorOverlayImageDescriptor( imageDescriptor.getImageData(), popup.getSelectedColor()) .createImage(); - disposeImage(button.getImage()); - button.setImage(overlyedImage); + disposeImage(toolItem.getImage()); + toolItem.setImage(overlyedImage); } return popup.getSelectedColor(); @@ -449,6 +470,7 @@ private void updateSpacing(int fromUnits, int toUnits) { String currentUnits = convertUnits(fromUnits, toUnits); + setWorkspaceProperty(WorkspaceViewerProperties.GRIDSPACING, convertStringToDouble(currentUnits).doubleValue()); } @@ -542,7 +564,8 @@ double pixels = convertToBase(value); if (pixels >= minValidValue && pixels <= maxValidValue) { setWorkspaceProperty(WorkspaceViewerProperties.GRIDSPACING, value); - setGridSpacing(value); + setGridSpacing(value); + } else { resetGridSpacing(); } @@ -604,6 +627,7 @@ gridVisibilityButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.VIEWGRID)); gridOrderButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.GRIDORDER)); snapToGridButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGRID)); + snapToGeometryButton.setSelection(getBooleanWorkspaceProperty(WorkspaceViewerProperties.SNAPTOGEOMETRY)); int rulerValue = getValue(WorkspaceViewerProperties.RULERUNIT); int styleValue = getValue(WorkspaceViewerProperties.GRIDLINESTYLE) - 1; @@ -800,6 +824,10 @@ if (!snapToGridButton.isDisposed()) { snapToGridButton.setSelection(getEventBoolean(event)); } + } else if (WorkspaceViewerProperties.SNAPTOGEOMETRY.equals(event.getProperty())) { + if (!snapToGeometryButton.isDisposed()) { + snapToGeometryButton.setSelection(getEventBoolean(event)); + } } else if (WorkspaceViewerProperties.GRIDORDER.equals(event.getProperty())) { if (!gridOrderButton.isDisposed()) { gridOrderButton.setSelection(getEventBoolean(event)); #P org.eclipse.gmf.runtime.diagram.ui Index: src/org/eclipse/gmf/runtime/diagram/ui/parts/DiagramEditor.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/parts/DiagramEditor.java,v retrieving revision 1.35 diff -u -r1.35 DiagramEditor.java --- src/org/eclipse/gmf/runtime/diagram/ui/parts/DiagramEditor.java 21 Nov 2007 17:57:28 -0000 1.35 +++ src/org/eclipse/gmf/runtime/diagram/ui/parts/DiagramEditor.java 7 Dec 2007 16:10:10 -0000 @@ -760,6 +760,7 @@ getActionRegistry().getAction(ActionFactory.DELETE.getId())); keyHandler.put(KeyStroke.getPressed(SWT.BS, 8, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId())); + keyHandler.put(/* CTRL + D */ KeyStroke.getPressed((char) 0x4, 100, SWT.CTRL), getActionRegistry().getAction( @@ -828,9 +829,9 @@ ((DiagramGraphicalViewer) getDiagramGraphicalViewer()) .hookWorkspacePreferenceStore(getWorkspaceViewerPreferenceStore()); } - + viewer.setRootEditPart(rootEP); - + viewer.setEditPartFactory(EditPartService.getInstance()); ContextMenuProvider provider = new DiagramContextMenuProvider(this, viewer); @@ -1176,13 +1177,17 @@ boolean snapToGrid = globalPreferenceStore .getBoolean(IPreferenceConstants.PREF_SNAP_TO_GRID); + + boolean snapToGeometry = globalPreferenceStore + .getBoolean(IPreferenceConstants.PREF_SNAP_TO_GEOMETRY); boolean viewRulers = globalPreferenceStore .getBoolean(IPreferenceConstants.PREF_SHOW_RULERS); // Set defaults for Grid store.setValue(WorkspaceViewerProperties.VIEWGRID, viewGrid); - store.setValue(WorkspaceViewerProperties.SNAPTOGRID, snapToGrid); + store.setValue(WorkspaceViewerProperties.SNAPTOGRID, snapToGrid); + store.setValue(WorkspaceViewerProperties.SNAPTOGEOMETRY, snapToGeometry); // Set defaults for Rulers store.setValue(WorkspaceViewerProperties.VIEWRULERS, viewRulers); @@ -1401,17 +1406,17 @@ } - // Snap to Grid + // Snap to Geometry getDiagramGraphicalViewer().setProperty( SnapToGeometry.PROPERTY_SNAP_ENABLED, Boolean.valueOf(getWorkspaceViewerPreferenceStore().getBoolean( - WorkspaceViewerProperties.SNAPTOGRID))); - - // Hide/Show Grid + WorkspaceViewerProperties.SNAPTOGEOMETRY))); + // Snap to Grid getDiagramGraphicalViewer().setProperty( SnapToGrid.PROPERTY_GRID_ENABLED, Boolean.valueOf(getWorkspaceViewerPreferenceStore().getBoolean( - WorkspaceViewerProperties.VIEWGRID))); + WorkspaceViewerProperties.SNAPTOGRID))); + // Hide/Show Grid getDiagramGraphicalViewer().setProperty( SnapToGrid.PROPERTY_GRID_VISIBLE, Boolean.valueOf(getWorkspaceViewerPreferenceStore().getBoolean( @@ -1420,7 +1425,7 @@ // Grid Origin (always 0, 0) Point origin = new Point(); getDiagramGraphicalViewer().setProperty( - SnapToGrid.PROPERTY_GRID_ORIGIN, origin); + SnapToGrid.PROPERTY_GRID_ORIGIN, origin); // Grid Spacing double dSpacing = ((DiagramRootEditPart) getDiagramEditPart().getRoot()) Index: src/org/eclipse/gmf/runtime/diagram/ui/tools/DragEditPartsTrackerEx.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/tools/DragEditPartsTrackerEx.java,v retrieving revision 1.8 diff -u -r1.8 DragEditPartsTrackerEx.java --- src/org/eclipse/gmf/runtime/diagram/ui/tools/DragEditPartsTrackerEx.java 21 Nov 2007 17:57:28 -0000 1.8 +++ src/org/eclipse/gmf/runtime/diagram/ui/tools/DragEditPartsTrackerEx.java 7 Dec 2007 16:10:10 -0000 @@ -120,15 +120,27 @@ /** * If the source is not in the operation set, it is not a move - * @see org.eclipse.gef.tools.DragEditPartsTracker#isMove() + * @see org.eclipse.gef.tool s.DragEditPartsTracker#isMove() */ - protected boolean isMove() { - if (!getOperationSet().contains(getSourceEditPart())) - return false; - return super.isMove(); + protected boolean isMove() { + for (int i = 0 ; i < getOperationSet().size(); i++){ + if (getOperationSet().get(i).equals(getSourceEditPart())){ + return super.isMove(); + } + //additional case for GroupEditPart, check the children + //this is for snap to geometry + if (getOperationSet().get(i) instanceof GroupEditPart){ + GroupEditPart currPart = (GroupEditPart)getOperationSet().get(i); + for (int j = 0 ; j < currPart.getChildren().size() ; j++){ + if (currPart.getChildren().get(j).equals(getSourceEditPart())){ + return super.isMove(); + } + } + } + } + return false; } - /* (non-Javadoc) * @see org.eclipse.gef.tools.AbstractTool#executeCurrentCommand() */ Index: src/org/eclipse/gmf/runtime/diagram/ui/preferences/IPreferenceConstants.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/preferences/IPreferenceConstants.java,v retrieving revision 1.5 diff -u -r1.5 IPreferenceConstants.java --- src/org/eclipse/gmf/runtime/diagram/ui/preferences/IPreferenceConstants.java 3 Oct 2006 15:02:05 -0000 1.5 +++ src/org/eclipse/gmf/runtime/diagram/ui/preferences/IPreferenceConstants.java 7 Dec 2007 16:10:10 -0000 @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2004, 2006 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -98,13 +98,18 @@ */ public static final String PREF_SNAP_TO_GRID = "GridRuler.snapToGrid"; //$NON-NLS-1$ /** - * ruler units pereference; Grid/Rulers Preference Page + * ruler units preference; Grid/Rulers Preference Page */ public static final String PREF_RULER_UNITS = "GridRuler.rulerUnits"; //$NON-NLS-1$ /** * grid spacing preference; Grid/Rulers Preference Page */ public static final String PREF_GRID_SPACING = "GridRuler.gridSpacing"; //$NON-NLS-1$ + /** + * snap to geometry preference; Grid/Rulers Preference Page + */ + public static final String PREF_SNAP_TO_GEOMETRY = "GridRuler.snapToGeometry"; //$NON-NLS-1$ + } Index: src/org/eclipse/gmf/runtime/diagram/ui/preferences/RulerGridPreferencePage.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/preferences/RulerGridPreferencePage.java,v retrieving revision 1.11 diff -u -r1.11 RulerGridPreferencePage.java --- src/org/eclipse/gmf/runtime/diagram/ui/preferences/RulerGridPreferencePage.java 16 Nov 2007 20:03:20 -0000 1.11 +++ src/org/eclipse/gmf/runtime/diagram/ui/preferences/RulerGridPreferencePage.java 7 Dec 2007 16:10:10 -0000 @@ -149,6 +149,7 @@ private String GRID_GROUP_LABEL = DiagramUIMessages.GridRulerPreferencePage_gridGroup_label; private String SHOW_GRID_LABEL = DiagramUIMessages.GridRulerPreferencePage_showGrid_label; private String SNAP_TO_GRID_LABEL = DiagramUIMessages.GridRulerPreferencePage_snapToGrid_label; + private String SNAP_TO_GEOMETRY_LABEL = DiagramUIMessages.GridRulerPreferencePage_snapToGeometry_label; private String GRID_SPACING_LABEL_INCHES = DiagramUIMessages.GridRulerPreferencePage_gridSpacing_label_inches; private String GRID_SPACING_LABEL_CM = DiagramUIMessages.GridRulerPreferencePage_gridSpacing_label_cm; private String GRID_SPACING_LABEL_PIXELS = DiagramUIMessages.GridRulerPreferencePage_gridSpacing_label_pixels; @@ -161,6 +162,7 @@ // Grid Field Editors private BooleanFieldEditor showGrid = null; private BooleanFieldEditor snapToGrid = null; + private BooleanFieldEditor snapToGeometry = null; private DoubleFieldEditor gridSpacing = null; private Composite dblGroup = null; @@ -338,6 +340,11 @@ SNAP_TO_GRID_LABEL, group); addField(snapToGrid); + snapToGeometry = new BooleanFieldEditor( + IPreferenceConstants.PREF_SNAP_TO_GEOMETRY, + SNAP_TO_GEOMETRY_LABEL, group); + addField(snapToGeometry); + addGridSpacing( group ); group.setLayoutData(gridData); @@ -400,6 +407,7 @@ } preferenceStore.setDefault(IPreferenceConstants.PREF_SHOW_GRID, false); preferenceStore.setDefault(IPreferenceConstants.PREF_SNAP_TO_GRID, true); + preferenceStore.setDefault(IPreferenceConstants.PREF_SNAP_TO_GEOMETRY, false); preferenceStore.setDefault(IPreferenceConstants.PREF_GRID_SPACING, 0.125); } Index: src/org/eclipse/gmf/runtime/diagram/ui/internal/properties/WorkspaceViewerProperties.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/internal/properties/WorkspaceViewerProperties.java,v retrieving revision 1.3 diff -u -r1.3 WorkspaceViewerProperties.java --- src/org/eclipse/gmf/runtime/diagram/ui/internal/properties/WorkspaceViewerProperties.java 21 Dec 2005 23:06:44 -0000 1.3 +++ src/org/eclipse/gmf/runtime/diagram/ui/internal/properties/WorkspaceViewerProperties.java 7 Dec 2007 16:10:10 -0000 @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2003 IBM Corporation and others. + * Copyright (c) 2003, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -37,6 +37,7 @@ public final String VIEWGRID = "rulergrid.viewgrid"; //$NON-NLS-1$ public final String GRIDLINESTYLE = "rulergrid.gridlinestyle"; //$NON-NLS-1$ public final String GRIDLINECOLOR = "rulergrid.gridlinecolor"; //$NON-NLS-1$ + public final String SNAPTOGEOMETRY = "rulergrid.snaptogeometry"; //$NON-NLS-1$ public final String SNAPTOGRID = "rulergrid.snaptogrid"; //$NON-NLS-1$ public final String GRIDORDER = "rulergrid.gridlevel"; //$NON-NLS-1$ public final String GRIDSPACING = "rulergrid.gridspacing"; //$NON-NLS-1$ Index: src/org/eclipse/gmf/runtime/diagram/ui/editparts/DiagramRootEditPart.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/editparts/DiagramRootEditPart.java,v retrieving revision 1.20 diff -u -r1.20 DiagramRootEditPart.java --- src/org/eclipse/gmf/runtime/diagram/ui/editparts/DiagramRootEditPart.java 26 Jan 2007 21:46:31 -0000 1.20 +++ src/org/eclipse/gmf/runtime/diagram/ui/editparts/DiagramRootEditPart.java 7 Dec 2007 16:10:10 -0000 @@ -510,6 +510,9 @@ getViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, event.getNewValue()); } else if (WorkspaceViewerProperties.SNAPTOGRID.equals(event.getProperty())) { // Set the state of the Snap to Grid Property + getViewer().setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, event.getNewValue()); + } else if (WorkspaceViewerProperties.SNAPTOGEOMETRY.equals(event.getProperty())) { + // Set the state of the Snap to Geometry Property getViewer().setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, event.getNewValue()); } else if (WorkspaceViewerProperties.GRIDORDER.equals(event.getProperty())) { // Set the grid level Index: src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.java,v retrieving revision 1.7 diff -u -r1.7 DiagramUIMessages.java --- src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.java 20 Nov 2007 20:26:16 -0000 1.7 +++ src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.java 7 Dec 2007 16:10:10 -0000 @@ -191,8 +191,7 @@ public static String RecalcPageBreaks_toolTip; public static String ViewGrid_textLabel; public static String ViewGrid_toolTip; - public static String SnapToGrid_textLabel; - public static String SnapToGrid_toolTip; + public static String SnapToGrid_textLabel; public static String ViewRuler_textLabel; public static String ViewRuler_toolTip; public static String CopyAction_Copy; @@ -302,6 +301,7 @@ public static String GridRulerPreferencePage_gridGroup_label; public static String GridRulerPreferencePage_showGrid_label; public static String GridRulerPreferencePage_snapToGrid_label; + public static String GridRulerPreferencePage_snapToGeometry_label; public static String GridRulerPreferencePage_gridSpacing_label_inches; public static String GridRulerPreferencePage_gridSpacing_label_cm; public static String GridRulerPreferencePage_gridSpacing_label_pixels; Index: src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.properties =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.properties,v retrieving revision 1.8 diff -u -r1.8 DiagramUIMessages.properties --- src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.properties 20 Nov 2007 20:26:16 -0000 1.8 +++ src/org/eclipse/gmf/runtime/diagram/ui/l10n/DiagramUIMessages.properties 7 Dec 2007 16:10:10 -0000 @@ -1,6 +1,6 @@ # ============================================================================== #*+------------------------------------------------------------------------+ -#*| Copyright (c) 2002,2003 IBM Corporation and others. | +#*| Copyright (c) 2002,2007 IBM Corporation and others. | #*| All rights reserved. This program and the accompanying materials | #*| are made available under the terms of the Eclipse Public License v1.0 | #*| which accompanies this distribution, and is available at | @@ -253,7 +253,6 @@ ViewGrid_textLabel=&Grid ViewGrid_toolTip=Toggle the grid lines on the diagram SnapToGrid_textLabel=&Snap to Grid -SnapToGrid_toolTip=Toggle Snap to Grid # --- Ruler actions --- ViewRuler_textLabel=&Rulers @@ -408,6 +407,7 @@ GridRulerPreferencePage_gridGroup_label=Grid options GridRulerPreferencePage_showGrid_label=Show &grid for new diagrams GridRulerPreferencePage_snapToGrid_label=Snap &to grid for new diagrams +GridRulerPreferencePage_snapToGeometry_label=S&nap to geometry for new diagrams GridRulerPreferencePage_gridSpacing_label_inches=Grid &spacing (in inches): GridRulerPreferencePage_gridSpacing_label_cm=Grid &spacing (in centimeters): GridRulerPreferencePage_gridSpacing_label_pixels=Grid &spacing (in pixels): Index: src/org/eclipse/gmf/runtime/diagram/ui/internal/editparts/SanpToHelperUtil.java =================================================================== RCS file: /cvsroot/modeling/org.eclipse.gmf/plugins/org.eclipse.gmf.runtime.diagram.ui/src/org/eclipse/gmf/runtime/diagram/ui/internal/editparts/SanpToHelperUtil.java,v retrieving revision 1.1 diff -u -r1.1 SanpToHelperUtil.java --- src/org/eclipse/gmf/runtime/diagram/ui/internal/editparts/SanpToHelperUtil.java 16 Jan 2007 14:54:00 -0000 1.1 +++ src/org/eclipse/gmf/runtime/diagram/ui/internal/editparts/SanpToHelperUtil.java 7 Dec 2007 16:10:10 -0000 @@ -22,19 +22,20 @@ import org.eclipse.gef.SnapToHelper; import org.eclipse.gef.rulers.RulerProvider; import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToGeometryEx; import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToGuidesEx; /** * @author mmostafa * - * Utility class used by the EditPart to allow them to adapt a SnapeHelper.class + * Utility class used by the EditPart to allow them to adapt a SnapToHelper.class * */ public class SanpToHelperUtil { /** - * returns the the appropiate snap helper(s), this method will always reach - * for the first reachable DiagramEditPart using the poassed edit part, then + * returns the the appropriate snap helper(s), this method will always reach + * for the first reachable DiagramEditPart using the passed edit part, then * use this Diagram edit part to get the snap helper * * @param editPart , @@ -47,12 +48,22 @@ while (diagramEditPart != null && !(diagramEditPart instanceof DiagramEditPart)) { diagramEditPart = (GraphicalEditPart) diagramEditPart.getParent(); - } + } if (diagramEditPart == null) return null; - List snapStrategies = new ArrayList(); + //for snap to geometry, attempt to locate a compartment as a parent + GraphicalEditPart parent = (GraphicalEditPart)editPart; + while (parent != null + && !(parent instanceof ISurfaceEditPart)){ + parent = (GraphicalEditPart) parent.getParent(); + } + + if (parent == null) + parent = diagramEditPart; + + List snapStrategies = new ArrayList(); EditPartViewer viewer = diagramEditPart.getViewer(); Boolean val = (Boolean) editPart.getViewer().getProperty( @@ -62,10 +73,16 @@ snapStrategies.add(new SnapToGuidesEx(diagramEditPart)); val = (Boolean) viewer - .getProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED); - if (val != null && val.booleanValue()) + .getProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED); + if (val != null && val.booleanValue()) + snapStrategies.add(new SnapToGeometryEx(parent)); + + val = (Boolean) viewer + .getProperty(SnapToGrid.PROPERTY_GRID_ENABLED); + + if (val != null && val.booleanValue()) snapStrategies.add(new SnapToGrid(diagramEditPart)); - + if (snapStrategies.size() == 0) return null; Index: src/org/eclipse/gmf/runtime/diagram/ui/internal/ruler/SnapToGeometryEx.java =================================================================== RCS file: src/org/eclipse/gmf/runtime/diagram/ui/internal/ruler/SnapToGeometryEx.java diff -N src/org/eclipse/gmf/runtime/diagram/ui/internal/ruler/SnapToGeometryEx.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/gmf/runtime/diagram/ui/internal/ruler/SnapToGeometryEx.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,90 @@ +/****************************************************************************** + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ****************************************************************************/ + +package org.eclipse.gmf.runtime.diagram.ui.internal.ruler; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.draw2d.geometry.Rectangle; +import org.eclipse.gef.GraphicalEditPart; +import org.eclipse.gef.SnapToGeometry; +import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart; +import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode; +import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil; + +/** + * Override to support HiMetrics * + * + * @author cli + */ +public class SnapToGeometryEx extends SnapToGeometry { + + protected static class EntryEx extends Entry { + + protected EntryEx(int type, int location) { + super(type, location); + } + } + + public SnapToGeometryEx(GraphicalEditPart container) { + super(container); + } + + + //This code will be required to translate the figure's coordinates + //accordingly if Bugzilla 188308 is fixed + + /* (non-Javadoc) + * @see org.eclipse.gef.SnapToGeometry#populateRowsAndCols(List parts) + */ + + // protected void populateRowsAndCols(List parts) { + // + // rows = new Entry[parts.size() * 3]; + // cols = new Entry[parts.size() * 3]; + // GraphicalEditPart diagramEditPart = (GraphicalEditPart)parts.get(0); + // + // while (diagramEditPart.getParent() != null){ + // diagramEditPart = (GraphicalEditPart)diagramEditPart.getParent(); + // if (diagramEditPart instanceof DiagramEditPart) break; + // } + // + // for (int i = 0; i < parts.size(); i++) { + // + // GraphicalEditPart child = (GraphicalEditPart)parts.get(i); + // Rectangle bounds = getFigureBounds(child).getCopy(); + // + // //translate the figure's coordinates to absolute, then relative + // //to the diagram (i.e the figure's layout constraint on the diagram) + // child.getFigure().translateToAbsolute(bounds); + // diagramEditPart.getFigure().translateToRelative(bounds); + // + // cols[i * 3] = new EntryEx(-1, bounds.x); + // rows[i * 3] = new EntryEx(-1, bounds.y); + // cols[i * 3 + 1] = new EntryEx(0, bounds.x + (bounds.width - 1) / 2); + // rows[i * 3 + 1] = new EntryEx(0, bounds.y + (bounds.height - 1) / 2); + // cols[i * 3 + 2] = new EntryEx(1, bounds.right() - 1); + // rows[i * 3 + 2] = new EntryEx(1, bounds.bottom() - 1); + // + // } + // } + + /* (non-Javadoc) + * @see org.eclipse.gef.SnapToGeometry#getThreshold() + */ + + protected double getThreshold() { + IMapMode mm = MapModeUtil.getMapMode(container.getFigure()); + return mm.DPtoLP((int) super.getThreshold()); + } + +}