Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src')
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/OverlayVisibilityIcon.java146
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SemanticFromGMFElement.java90
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/UMLDiagramEditorUtil.java62
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/DiagramAdapterFactory.java82
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/GMFMultiDiagramAdapterFactory.java118
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java318
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshCommand.java116
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java290
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateEditBasedElementCommand.java806
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateShapeCompartmentViewCommand.java188
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultActionHandler.java54
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java248
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DeferredSnapToGridCommand.java510
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java318
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java296
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/ISemanticHintAdapter.java56
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertFloatingLabelFromMapCommand.java332
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForDo.java70
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForUndo.java62
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SelectAndExecuteCommand.java388
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticAdapter.java198
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticElementAdapter.java176
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SetNodeVisibilityCommand.java94
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/requests/ShowHideRelatedLinkRequest.java156
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AbstractCustomStyleListValueCommand.java200
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddAllCustomStyleListValueCommand.java90
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddCustomStyleListValueCommand.java88
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableList.java48
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableValue.java98
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableList.java50
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableValue.java100
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableList.java48
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableValue.java98
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableList.java48
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableValue.java98
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleObservableList.java358
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveAllCustomStyleListValueCommand.java76
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveCustomStyleListValueCommand.java72
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/SetCustomStyleListValueCommand.java78
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ConnectionDecorationRegistry.java276
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceDecoration.java140
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceMarker.java270
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/OpenArrowConnectionDecoration.java122
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowEmptyConnectionDecoration.java130
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowFilledConnectionDecoration.java126
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondEmptyConnectionDecoration.java152
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondFilledConnectionDecoration.java146
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java690
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IBorderItemWithLocator.java54
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IPapyrusEditPart.java64
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IShapeCompartmentEditPart.java52
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java92
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ResizeableListCompartmentEditPart.java174
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/XYLayoutShapeCompartmentEditPart.java110
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/DefaultCompartmentSemanticEditPolicy.java92
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/EdgeWithNoSemanticElementRepresentationImpl.java240
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ExternalReferenceEditPolicy.java250
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/FollowSVGSymbolEditPolicy.java172
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/GetChildLayoutEditPolicy.java136
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/HighlightEditPolicy.java150
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/IDiagramInformationProviderEditPolicy.java80
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java408
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/NoSemanticParserEditPolicy.java106
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusConnectionEndEditPolicy.java106
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java426
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java434
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java600
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java90
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/SlidableEllipseAnchor.java154
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java900
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ICustomNodePlate.java76
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/IPapyrusNodeFigure.java236
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusAnchorableWrappingLabel.java402
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java242
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ScalableCompartmentFigure.java74
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ShapeFlowLayout.java654
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/SubCompartmentLayoutManager.java220
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java134
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java276
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java58
-rwxr-xr-xplugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java756
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java212
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java246
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/SemanticElementHelper.java224
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/listener/CustomStyleListener.java266
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferenceInitializer.java54
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferencePage.java70
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferences.java72
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractShapeCompartmentEditPartProvider.java170
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractViewProvider.java644
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java202
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java110
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/IThemeInitializer.java40
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/LineStyleLabelProvider.java252
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationFilteredLabelProvider.java114
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/RestrictedAbstractEditPartProvider.java122
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecoratorProvider.java152
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ThemeInitializerManager.java102
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/UnitsLabelProvider.java224
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/reconciler/DiagramReconcilersReader.java350
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandDragTracker.java94
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandSelectionTool.java1700
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/SelectionToolPaletteFactory.java264
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/WorkspaceExtendedPaletteProvider.java132
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java692
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/CreateProviderNotificationManagersOperation.java148
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetAllShapeProvidersOperation.java98
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetSVGDocumentForViewOperation.java120
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapeProviderByIdentifierOperation.java108
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapesForViewOperation.java120
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/IShapeProviderOperation.java42
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/NotificationManager.java156
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ProviderNotificationManager.java118
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/SVGPostProcessor.java94
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ShapeProviderConfiguration.java134
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/BorderNodeSnapHelper.java72
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/NodeSnapHelper.java918
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointHandle.java174
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointTracker.java220
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragBorderNodeEditPartTrackerEx.java118
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragEditPartsTrackerEx.java754
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java118
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/AbstractTool.java3576
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/CustomDragEditPartsTracker.java1440
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DelayedDirectEditHelper.java258
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DragEditPartsTrackerEx.java642
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/SelectEditPartTracker.java518
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/TargetingTool.java914
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/copy/AbstractCopyStrategy.java204
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/EditPartSyncTrigger.java254
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodePositionSyncFeature.java314
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodeSizeSyncFeature.java328
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java414
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/undocontext/UndoContextServiceFactory.java188
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CommandIds.java64
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CopyPasteUtil.java370
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/EditPartUtils.java224
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java302
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/HighlightUtil.java472
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/LineStyleEnum.java224
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PortPositionEnum.java128
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PositionEnum.java196
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ServiceUtilsForEditPart.java112
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConstants.java96
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConverterUtils.java216
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/Util.java96
-rw-r--r--plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ViewDescriptorUtil.java46
147 files changed, 19205 insertions, 19205 deletions
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/OverlayVisibilityIcon.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/OverlayVisibilityIcon.java
index 508c506f5d9..039e50763ea 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/OverlayVisibilityIcon.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/OverlayVisibilityIcon.java
@@ -1,73 +1,73 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common;
-
-import org.eclipse.jface.resource.CompositeImageDescriptor;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.ImageData;
-import org.eclipse.swt.graphics.Point;
-
-/**
- * This class is used to add UML visibility decoration over stereotype icons
- *
- */
-public class OverlayVisibilityIcon extends CompositeImageDescriptor {
-
- /**
- * Initial image
- */
- private Image initialImage;
-
- /**
- * Initial image
- */
- private ImageDescriptor visDesc;
-
- /**
- * Size of the initial image
- */
- private Point size;
-
- /**
- * Main constructor
- */
- public OverlayVisibilityIcon(Image initialImage, ImageDescriptor visibilityDescriptor) {
- this.initialImage = initialImage;
- this.visDesc = visibilityDescriptor;
- this.size = new Point(initialImage.getBounds().width, initialImage.getBounds().height);
- }
-
- @Override
- protected void drawCompositeImage(int arg0, int arg1) {
- // Draw the base image
- drawImage(initialImage.getImageData(), 0, 0);
- ImageData imageData = visDesc.getImageData();
- drawImage(imageData, size.x - imageData.width, size.y - imageData.height);
- }
-
- @Override
- protected Point getSize() {
- return size;
- }
-
- /**
- * Get the image formed by overlaying different images on the base image
- *
- * @return composite image
- */
- public Image getImage() {
- return createImage();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common;
+
+import org.eclipse.jface.resource.CompositeImageDescriptor;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.Point;
+
+/**
+ * This class is used to add UML visibility decoration over stereotype icons
+ *
+ */
+public class OverlayVisibilityIcon extends CompositeImageDescriptor {
+
+ /**
+ * Initial image
+ */
+ private Image initialImage;
+
+ /**
+ * Initial image
+ */
+ private ImageDescriptor visDesc;
+
+ /**
+ * Size of the initial image
+ */
+ private Point size;
+
+ /**
+ * Main constructor
+ */
+ public OverlayVisibilityIcon(Image initialImage, ImageDescriptor visibilityDescriptor) {
+ this.initialImage = initialImage;
+ this.visDesc = visibilityDescriptor;
+ this.size = new Point(initialImage.getBounds().width, initialImage.getBounds().height);
+ }
+
+ @Override
+ protected void drawCompositeImage(int arg0, int arg1) {
+ // Draw the base image
+ drawImage(initialImage.getImageData(), 0, 0);
+ ImageData imageData = visDesc.getImageData();
+ drawImage(imageData, size.x - imageData.width, size.y - imageData.height);
+ }
+
+ @Override
+ protected Point getSize() {
+ return size;
+ }
+
+ /**
+ * Get the image formed by overlaying different images on the base image
+ *
+ * @return composite image
+ */
+ public Image getImage() {
+ return createImage();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SemanticFromGMFElement.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SemanticFromGMFElement.java
index 8d57daee765..eb6f17dbdd1 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SemanticFromGMFElement.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/SemanticFromGMFElement.java
@@ -1,45 +1,45 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.papyrus.infra.core.IElementWithSemantic;
-
-/**
- * this class is used to obtain the semantic element for element of a gmf diagram
- *
- */
-public class SemanticFromGMFElement implements IElementWithSemantic {
- /**
- *
- * @see org.eclipse.papyrus.infra.core.IElementWithSemantic#getSemanticElement(java.lang.Object)
- *
- * @param wrapper
- * can be for examplean editpart of gmf
- * @return the semantic element linked to this or null element
- */
- @Override
- public Object getSemanticElement(Object wrapper) {
- if (wrapper instanceof IGraphicalEditPart) {
- return ((IGraphicalEditPart) wrapper).resolveSemanticElement();
- }
- if (wrapper instanceof IAdaptable) {
- return ((IAdaptable) wrapper).getAdapter(EObject.class);
- }
- return null;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.papyrus.infra.core.IElementWithSemantic;
+
+/**
+ * this class is used to obtain the semantic element for element of a gmf diagram
+ *
+ */
+public class SemanticFromGMFElement implements IElementWithSemantic {
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.IElementWithSemantic#getSemanticElement(java.lang.Object)
+ *
+ * @param wrapper
+ * can be for examplean editpart of gmf
+ * @return the semantic element linked to this or null element
+ */
+ @Override
+ public Object getSemanticElement(Object wrapper) {
+ if (wrapper instanceof IGraphicalEditPart) {
+ return ((IGraphicalEditPart) wrapper).resolveSemanticElement();
+ }
+ if (wrapper instanceof IAdaptable) {
+ return ((IAdaptable) wrapper).getAdapter(EObject.class);
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/UMLDiagramEditorUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/UMLDiagramEditorUtil.java
index 9ba8c7e52d3..30231dd0d52 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/UMLDiagramEditorUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/UMLDiagramEditorUtil.java
@@ -1,31 +1,31 @@
-/*****************************************************************************
- * Copyright (c) 2008 CEA LIST.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.xmi.XMLResource;
-
-public class UMLDiagramEditorUtil {
-
- public static Map getSaveOptions() {
- Map saveOptions = new HashMap();
- saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
- saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
- return saveOptions;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2008 CEA LIST.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.xmi.XMLResource;
+
+public class UMLDiagramEditorUtil {
+
+ public static Map getSaveOptions() {
+ Map saveOptions = new HashMap();
+ saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); //$NON-NLS-1$
+ saveOptions.put(Resource.OPTION_SAVE_ONLY_IF_CHANGED, Resource.OPTION_SAVE_ONLY_IF_CHANGED_MEMORY_BUFFER);
+ return saveOptions;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/DiagramAdapterFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/DiagramAdapterFactory.java
index 4e8d6aae0e7..9efa8817d8a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/DiagramAdapterFactory.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/DiagramAdapterFactory.java
@@ -1,41 +1,41 @@
-/*****************************************************************************
- * Copyright (c) 2011 Atos
- *
- *
- * 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:
- * Tristan FAURE - tristan.faure@atos.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.adapter;
-
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenable;
-import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenableWithContainer;
-
-@SuppressWarnings("rawtypes")
-public class DiagramAdapterFactory implements IAdapterFactory {
-
- @Override
- public Object getAdapter(Object adaptableObject, Class adapterType) {
- if (adapterType == IOpenable.class) {
- if (adaptableObject instanceof Diagram) {
- Diagram diagram = (Diagram) adaptableObject;
- return new IOpenableWithContainer.Openable(adaptableObject, diagram.getElement());
- }
- }
- return null;
- }
-
- @Override
- public Class[] getAdapterList() {
- return new Class[] { IOpenable.class };
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 Atos
+ *
+ *
+ * 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:
+ * Tristan FAURE - tristan.faure@atos.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.adapter;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenable;
+import org.eclipse.papyrus.infra.core.sasheditor.di.contentprovider.IOpenableWithContainer;
+
+@SuppressWarnings("rawtypes")
+public class DiagramAdapterFactory implements IAdapterFactory {
+
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adapterType == IOpenable.class) {
+ if (adaptableObject instanceof Diagram) {
+ Diagram diagram = (Diagram) adaptableObject;
+ return new IOpenableWithContainer.Openable(adaptableObject, diagram.getElement());
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Class[] getAdapterList() {
+ return new Class[] { IOpenable.class };
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/GMFMultiDiagramAdapterFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/GMFMultiDiagramAdapterFactory.java
index 70d5c8cc4ce..b436cc693ec 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/GMFMultiDiagramAdapterFactory.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/adapter/GMFMultiDiagramAdapterFactory.java
@@ -1,59 +1,59 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.adapter;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IAdapterFactory;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
-import org.eclipse.ui.IEditorPart;
-
-
-public class GMFMultiDiagramAdapterFactory implements IAdapterFactory {
-
- @Override
- public Object getAdapter(Object adaptableObject, Class adapterType) {
- if (adaptableObject instanceof IMultiDiagramEditor) {
- IEditorPart nestedEditor = ((IMultiDiagramEditor) adaptableObject).getActiveEditor();
-
- // The nestedEditor may or may not handle these cases.
- if (nestedEditor != null && nestedEditor instanceof IAdaptable) {
- if (adapterType == IDiagramGraphicalViewer.class) {
- return ((IAdaptable) nestedEditor).getAdapter(IDiagramGraphicalViewer.class);
- }
-
- if (adapterType == Diagram.class) {
- return ((IAdaptable) nestedEditor).getAdapter(Diagram.class);
- }
-
- if (adapterType == DiagramEditPart.class) {
- return ((IAdaptable) nestedEditor).getAdapter(DiagramEditPart.class);
- }
-
- if (adapterType == IDiagramWorkbenchPart.class) {
- return ((IAdaptable) nestedEditor).getAdapter(IDiagramWorkbenchPart.class);
- }
- }
- }
-
- return null;
- }
-
- @Override
- public Class<?>[] getAdapterList() {
- return new Class<?>[] { IMultiDiagramEditor.class };
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.adapter;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramGraphicalViewer;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
+import org.eclipse.ui.IEditorPart;
+
+
+public class GMFMultiDiagramAdapterFactory implements IAdapterFactory {
+
+ @Override
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adaptableObject instanceof IMultiDiagramEditor) {
+ IEditorPart nestedEditor = ((IMultiDiagramEditor) adaptableObject).getActiveEditor();
+
+ // The nestedEditor may or may not handle these cases.
+ if (nestedEditor != null && nestedEditor instanceof IAdaptable) {
+ if (adapterType == IDiagramGraphicalViewer.class) {
+ return ((IAdaptable) nestedEditor).getAdapter(IDiagramGraphicalViewer.class);
+ }
+
+ if (adapterType == Diagram.class) {
+ return ((IAdaptable) nestedEditor).getAdapter(Diagram.class);
+ }
+
+ if (adapterType == DiagramEditPart.class) {
+ return ((IAdaptable) nestedEditor).getAdapter(DiagramEditPart.class);
+ }
+
+ if (adapterType == IDiagramWorkbenchPart.class) {
+ return ((IAdaptable) nestedEditor).getAdapter(IDiagramWorkbenchPart.class);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public Class<?>[] getAdapterList() {
+ return new Class<?>[] { IMultiDiagramEditor.class };
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java
index 5a72674e788..cd666865075 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractFixEdgeAnchorDeferredCommand.java
@@ -1,159 +1,159 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.NodeEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.FixAnchorHelper;
-
-
-/**
- *
- * an abstract command used to update anchor location in the notation
- * 430702: [Diagram] Moving source of a link moves the target too.
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=430702
- */
-public abstract class AbstractFixEdgeAnchorDeferredCommand extends AbstractTransactionalCommand {
-
- /** the diagram editpart used to get the editpart registry */
- private IGraphicalEditPart containerEP;
-
- /**
- * the fix anchor helper
- */
- private FixAnchorHelper helper;
-
- private static final Point orig = new Point(0, 0);
-
- private static final Dimension nullDimension = new Dimension(0, 0);
-
- public AbstractFixEdgeAnchorDeferredCommand(final TransactionalEditingDomain editingDomain, final String commandTitle, final IGraphicalEditPart containerEP) {
- super(editingDomain, commandTitle, null);
- this.containerEP = containerEP;
- this.helper = new FixAnchorHelper(editingDomain);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
- *
- * @return
- */
- @Override
- @SuppressWarnings("rawtypes")
- public List getAffectedFiles() {
- if (containerEP != null) {
- View view = (View) containerEP.getModel();
- if (view != null) {
- IFile f = WorkspaceSynchronizer.getFile(view.eResource());
- return f != null ? Collections.singletonList(f) : Collections.EMPTY_LIST;
- }
- }
- return super.getAffectedFiles();
- }
-
- /**
- *
- * @param connectionToRefresh
- * the connection edit part to refresh
- * @param commandToContribute
- * the command to contribute (as parameter to avoid to create several compound command
- */
- protected void addFixAnchorCommand(final AbstractConnectionEditPart connectionToRefresh, final CompoundCommand commandToContribute) {
- Assert.isNotNull(commandToContribute);
- final EditPart sourceEditPart = connectionToRefresh.getSource();
- final EditPart targetEditPart = connectionToRefresh.getTarget();
- if (sourceEditPart instanceof NodeEditPart) {
- final INodeEditPart nodeEditPart = (INodeEditPart) sourceEditPart;
- PrecisionRectangle nodeBounds = new PrecisionRectangle(nodeEditPart.getFigure().getBounds());
- nodeEditPart.getFigure().translateToAbsolute(nodeBounds);
- final Command cc = this.helper.getFixAnchorCommand(nodeEditPart, nodeBounds, nodeBounds, connectionToRefresh, orig, nullDimension, true);
- if (cc != null) {
- commandToContribute.add(cc);
- }
- }
- if (targetEditPart instanceof NodeEditPart) {
- final INodeEditPart nodeEditPart = (INodeEditPart) targetEditPart;
- PrecisionRectangle nodeBounds = new PrecisionRectangle(nodeEditPart.getFigure().getBounds());
- nodeEditPart.getFigure().translateToAbsolute(nodeBounds);
- final Command cc = this.helper.getFixAnchorCommand(nodeEditPart, nodeBounds, nodeBounds, connectionToRefresh, orig, nullDimension, false);
- if (cc != null) {
- commandToContribute.add(cc);
- }
- }
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
- *
- */
- @Override
- protected void cleanup() {
- this.containerEP = null;// for garbage collection
- this.helper = null;
- super.cleanup();
- }
-
- /**
- * gets the container edit part's figure
- *
- * @return the container figure
- */
- protected final IFigure getContainerFigure() {
- return this.containerEP.getFigure();
- }
-
- /**
- * gets the container edit part
- *
- * @return the container edit part
- */
- protected final IGraphicalEditPart getContainerEP() {
- return this.containerEP;
- }
-
- /**
- *
- * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
- *
- * @return
- */
- @Override
- public boolean canExecute() {
- return super.canExecute() && this.helper != null && this.containerEP != null;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.NodeEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.FixAnchorHelper;
+
+
+/**
+ *
+ * an abstract command used to update anchor location in the notation
+ * 430702: [Diagram] Moving source of a link moves the target too.
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=430702
+ */
+public abstract class AbstractFixEdgeAnchorDeferredCommand extends AbstractTransactionalCommand {
+
+ /** the diagram editpart used to get the editpart registry */
+ private IGraphicalEditPart containerEP;
+
+ /**
+ * the fix anchor helper
+ */
+ private FixAnchorHelper helper;
+
+ private static final Point orig = new Point(0, 0);
+
+ private static final Dimension nullDimension = new Dimension(0, 0);
+
+ public AbstractFixEdgeAnchorDeferredCommand(final TransactionalEditingDomain editingDomain, final String commandTitle, final IGraphicalEditPart containerEP) {
+ super(editingDomain, commandTitle, null);
+ this.containerEP = containerEP;
+ this.helper = new FixAnchorHelper(editingDomain);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
+ *
+ * @return
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ public List getAffectedFiles() {
+ if (containerEP != null) {
+ View view = (View) containerEP.getModel();
+ if (view != null) {
+ IFile f = WorkspaceSynchronizer.getFile(view.eResource());
+ return f != null ? Collections.singletonList(f) : Collections.EMPTY_LIST;
+ }
+ }
+ return super.getAffectedFiles();
+ }
+
+ /**
+ *
+ * @param connectionToRefresh
+ * the connection edit part to refresh
+ * @param commandToContribute
+ * the command to contribute (as parameter to avoid to create several compound command
+ */
+ protected void addFixAnchorCommand(final AbstractConnectionEditPart connectionToRefresh, final CompoundCommand commandToContribute) {
+ Assert.isNotNull(commandToContribute);
+ final EditPart sourceEditPart = connectionToRefresh.getSource();
+ final EditPart targetEditPart = connectionToRefresh.getTarget();
+ if (sourceEditPart instanceof NodeEditPart) {
+ final INodeEditPart nodeEditPart = (INodeEditPart) sourceEditPart;
+ PrecisionRectangle nodeBounds = new PrecisionRectangle(nodeEditPart.getFigure().getBounds());
+ nodeEditPart.getFigure().translateToAbsolute(nodeBounds);
+ final Command cc = this.helper.getFixAnchorCommand(nodeEditPart, nodeBounds, nodeBounds, connectionToRefresh, orig, nullDimension, true);
+ if (cc != null) {
+ commandToContribute.add(cc);
+ }
+ }
+ if (targetEditPart instanceof NodeEditPart) {
+ final INodeEditPart nodeEditPart = (INodeEditPart) targetEditPart;
+ PrecisionRectangle nodeBounds = new PrecisionRectangle(nodeEditPart.getFigure().getBounds());
+ nodeEditPart.getFigure().translateToAbsolute(nodeBounds);
+ final Command cc = this.helper.getFixAnchorCommand(nodeEditPart, nodeBounds, nodeBounds, connectionToRefresh, orig, nullDimension, false);
+ if (cc != null) {
+ commandToContribute.add(cc);
+ }
+ }
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
+ *
+ */
+ @Override
+ protected void cleanup() {
+ this.containerEP = null;// for garbage collection
+ this.helper = null;
+ super.cleanup();
+ }
+
+ /**
+ * gets the container edit part's figure
+ *
+ * @return the container figure
+ */
+ protected final IFigure getContainerFigure() {
+ return this.containerEP.getFigure();
+ }
+
+ /**
+ * gets the container edit part
+ *
+ * @return the container edit part
+ */
+ protected final IGraphicalEditPart getContainerEP() {
+ return this.containerEP;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && this.helper != null && this.containerEP != null;
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshCommand.java
index 16369c6d533..402e5c9c46a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshCommand.java
@@ -1,58 +1,58 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.RootEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Refresh the {@link IFigure} of a given {@link GraphicalEditPart}.
- * @since 3.0
- */
-public abstract class AbstractRefreshCommand extends Command {
-
- private final GraphicalEditPart editPartToRefresh;
-
- private final RootEditPart rootEditPart;
-
- public AbstractRefreshCommand(final GraphicalEditPart editPartToRefresh) {
- this.editPartToRefresh = editPartToRefresh;
- this.rootEditPart = editPartToRefresh.getRoot();
- }
-
- public GraphicalEditPart getEditPartToRefresh() {
- return this.editPartToRefresh;
- }
-
- protected void refresh() {
- Display.getDefault().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- if (AbstractRefreshCommand.this.editPartToRefresh.isActive()) {
- DiagramHelper.refresh(AbstractRefreshCommand.this.editPartToRefresh, true);
- // this is needed in order to update the bounds of the Figures from their layout manager constraints
- AbstractRefreshCommand.this.editPartToRefresh.getFigure().invalidateTree();
- } else if (AbstractRefreshCommand.this.rootEditPart.isActive()) {
- /*
- * If the EditPart we needed to refresh is not active anymore, then it probably means that we undid its
- * creation, and re-created the object as part of a redo, with a different EditPart. In this case, just
- * refresh everything.
- */
- DiagramHelper.refresh(AbstractRefreshCommand.this.rootEditPart, true);
- }
- }
- });
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Refresh the {@link IFigure} of a given {@link GraphicalEditPart}.
+ * @since 3.0
+ */
+public abstract class AbstractRefreshCommand extends Command {
+
+ private final GraphicalEditPart editPartToRefresh;
+
+ private final RootEditPart rootEditPart;
+
+ public AbstractRefreshCommand(final GraphicalEditPart editPartToRefresh) {
+ this.editPartToRefresh = editPartToRefresh;
+ this.rootEditPart = editPartToRefresh.getRoot();
+ }
+
+ public GraphicalEditPart getEditPartToRefresh() {
+ return this.editPartToRefresh;
+ }
+
+ protected void refresh() {
+ Display.getDefault().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ if (AbstractRefreshCommand.this.editPartToRefresh.isActive()) {
+ DiagramHelper.refresh(AbstractRefreshCommand.this.editPartToRefresh, true);
+ // this is needed in order to update the bounds of the Figures from their layout manager constraints
+ AbstractRefreshCommand.this.editPartToRefresh.getFigure().invalidateTree();
+ } else if (AbstractRefreshCommand.this.rootEditPart.isActive()) {
+ /*
+ * If the EditPart we needed to refresh is not active anymore, then it probably means that we undid its
+ * creation, and re-created the object as part of a redo, with a different EditPart. In this case, just
+ * refresh everything.
+ */
+ DiagramHelper.refresh(AbstractRefreshCommand.this.rootEditPart, true);
+ }
+ }
+ });
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java
index d8953fcdb79..ece7b6c3566 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/AbstractRefreshConnectionElementsRunnable.java
@@ -1,146 +1,146 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.List;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-
-
-/**
- *
- * abstract runnable used to refresh the connection, source and target editparts
- *
- */
-public abstract class AbstractRefreshConnectionElementsRunnable<T> implements RunnableWithResult<T> {
-
- /**
- * the status of the runnable
- */
- private IStatus status;
-
- /**
- * the result of the runnable
- */
- private T result;
-
- /**
- * the container editpart of the refreshed connection
- */
- private final IGraphicalEditPart containerEP;
-
- /**
- *
- * Constructor.
- *
- * @param containerEP
- * the editpart owning the connection
- */
- public AbstractRefreshConnectionElementsRunnable(final IGraphicalEditPart containerEP) {
- this.containerEP = containerEP;
- }
-
- /**
- *
- * @see org.eclipse.emf.transaction.RunnableWithResult#getResult()
- *
- * @return
- */
- @Override
- public final T getResult() {
- return result;
- }
-
- /**
- *
- * @see org.eclipse.emf.transaction.RunnableWithResult#setStatus(org.eclipse.core.runtime.IStatus)
- *
- * @param status
- * set the new status for the runnable
- */
- @Override
- public final void setStatus(IStatus status) {
- this.status = status;
- }
-
- /**
- *
- * @see org.eclipse.emf.transaction.RunnableWithResult#getStatus()
- *
- * @return
- * the status of the runnable
- */
- @Override
- public final IStatus getStatus() {
- return status;
- }
-
- /**
- *
- * @return
- * the container edit part
- */
- protected final IGraphicalEditPart getContainerEditPart() {
- return this.containerEP;
- }
-
- /**
- *
- * @param connectionToRefresh
- * the connection edit part to refresh
- */
- protected final void refreshConnection(final AbstractConnectionEditPart connectionToRefresh) {
- connectionToRefresh.refresh();
- final EditPart sourceEp = connectionToRefresh.getSource();
- if (sourceEp != null) {
- sourceEp.refresh();
- }
- final EditPart targetEP = connectionToRefresh.getTarget();
- if (targetEP != null) {
- targetEP.refresh();
- }
- @SuppressWarnings("unchecked")
- List<? extends EditPart> childrens = connectionToRefresh.getChildren();
- for (EditPart nextChild : childrens) {
- nextChild.refresh();
- }
- // to force the call to the router, to update the figure
- connectionToRefresh.getFigure().validate();
- }
-
- /**
- *
- * @return
- * the figure for the container edit part
- */
- protected final IFigure getContainerFigure() {
- return this.containerEP.getFigure();
- }
-
- /**
- *
- * @param result
- * set the result of the runnable
- */
- protected final void setResult(T result) {
- this.result = result;
- }
-
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.List;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+
+
+/**
+ *
+ * abstract runnable used to refresh the connection, source and target editparts
+ *
+ */
+public abstract class AbstractRefreshConnectionElementsRunnable<T> implements RunnableWithResult<T> {
+
+ /**
+ * the status of the runnable
+ */
+ private IStatus status;
+
+ /**
+ * the result of the runnable
+ */
+ private T result;
+
+ /**
+ * the container editpart of the refreshed connection
+ */
+ private final IGraphicalEditPart containerEP;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param containerEP
+ * the editpart owning the connection
+ */
+ public AbstractRefreshConnectionElementsRunnable(final IGraphicalEditPart containerEP) {
+ this.containerEP = containerEP;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.transaction.RunnableWithResult#getResult()
+ *
+ * @return
+ */
+ @Override
+ public final T getResult() {
+ return result;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.transaction.RunnableWithResult#setStatus(org.eclipse.core.runtime.IStatus)
+ *
+ * @param status
+ * set the new status for the runnable
+ */
+ @Override
+ public final void setStatus(IStatus status) {
+ this.status = status;
+ }
+
+ /**
+ *
+ * @see org.eclipse.emf.transaction.RunnableWithResult#getStatus()
+ *
+ * @return
+ * the status of the runnable
+ */
+ @Override
+ public final IStatus getStatus() {
+ return status;
+ }
+
+ /**
+ *
+ * @return
+ * the container edit part
+ */
+ protected final IGraphicalEditPart getContainerEditPart() {
+ return this.containerEP;
+ }
+
+ /**
+ *
+ * @param connectionToRefresh
+ * the connection edit part to refresh
+ */
+ protected final void refreshConnection(final AbstractConnectionEditPart connectionToRefresh) {
+ connectionToRefresh.refresh();
+ final EditPart sourceEp = connectionToRefresh.getSource();
+ if (sourceEp != null) {
+ sourceEp.refresh();
+ }
+ final EditPart targetEP = connectionToRefresh.getTarget();
+ if (targetEP != null) {
+ targetEP.refresh();
+ }
+ @SuppressWarnings("unchecked")
+ List<? extends EditPart> childrens = connectionToRefresh.getChildren();
+ for (EditPart nextChild : childrens) {
+ nextChild.refresh();
+ }
+ // to force the call to the router, to update the figure
+ connectionToRefresh.getFigure().validate();
+ }
+
+ /**
+ *
+ * @return
+ * the figure for the container edit part
+ */
+ protected final IFigure getContainerFigure() {
+ return this.containerEP.getFigure();
+ }
+
+ /**
+ *
+ * @param result
+ * set the result of the runnable
+ */
+ protected final void setResult(T result) {
+ this.result = result;
+ }
+
}; \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateEditBasedElementCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateEditBasedElementCommand.java
index 1d668556598..9b6e3bbb557 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateEditBasedElementCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateEditBasedElementCommand.java
@@ -1,403 +1,403 @@
-/*****************************************************************************
- * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
- * Remi Schnekenburger (CEA LIST) - Initial API and implementation
- * Christian W. Damus (CEA) - bug 431109
- * Christian W. Damus - bug 507618
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.commands.operations.IUndoableOperation;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.command.UnexecutableCommand;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EFactory;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EReference;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.edit.command.CommandParameter;
-import org.eclipse.emf.edit.command.CreateChildCommand;
-import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
-import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.CompositeEMFOperation;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.dialogs.ElementListSelectionDialog;
-
-/**
- * Creation command based on the metamodel.edit framework instead of relying on
- * the defaut GMF creation mechanism.
- * <P>
- * So the creation of elements is similar to the creation customized in the metamodel itself, which can be interesting for metamodels like UML. This can avoid specific code for example for Activity.createNode() list of commands.
- * </P>
- * <P>
- * The implementation relies on a composite command that delegates first the basic creation of the element to the metamodel.edit service.<BR/>
- * A second operation computes during execution the list of additional commands to configure the newly created element. For example, the name of the new element can be set in configure commands. Note: the configure command needs the newly created command, so
- * the list of operations to perform is unknown until the composite operation is executed. The executability of the 2nd set of commands can be hard to test.
- * </P>
- */
-public class CreateEditBasedElementCommand extends CreateElementCommand {
-
- protected final class CreateEditBasedElementTransactionalCommand extends AbstractTransactionalCommand {
- private Collection<Command> possibleCommands;
- private Command commandDone;
-
- protected CreateEditBasedElementTransactionalCommand(TransactionalEditingDomain domain, String label, List<?> affectedFiles) {
- super(domain, label, affectedFiles);
- }
-
- @Override
- public boolean canExecute() {
- // Optimistically enable if the request would have to create
- // the container, because
- // we can't do that in a read-only context (when not
- // actually executing)
- return canCreateChild() && (!hasElementToEdit() || !(getPossibleCommands().isEmpty()));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- Command command = prepareCommand();
- if (command.canExecute()) {
- // create an IUndoableOperation => undo is relying on
- // the execution of this command
- command.execute();
- return CommandResult.newOKCommandResult(newElement);
- }
- return CommandResult.newErrorCommandResult("Impossible to create Element");
- }
-
- protected Collection<Command> getPossibleCommands() {
- if (possibleCommands == null) {
- possibleCommands = new HashSet<Command>();
- EClass eClass = getElementType().getEClass();
- List<EClass> eClassesToCreateCommandsFor = new ArrayList<EClass>();
- if (eClass.isAbstract()) {
- // If we didn't receive a hint on the eClass to create
- if (eClassHint == null) {
- eClassesToCreateCommandsFor.addAll(EMFHelper.getSubclassesOf(eClass, true));
- } else {
- eClassesToCreateCommandsFor.add(eClassHint);
- }
- } else {
- eClassesToCreateCommandsFor.add(eClass);
- }
- if (eClassesToCreateCommandsFor.isEmpty()) {
- possibleCommands.add(UnexecutableCommand.INSTANCE);
- }
- EObject element = getElementToEdit();
- if (element != null) {
- // Do the default element creation
- EReference containment = getContainmentFeature();
- if (containment != null) {
- IEditingDomainItemProvider editingDomainItemProvider = AdapterFactoryEditingDomain.getEditingDomainItemProviderFor(element);
- ResourceSet resourceSet = EMFHelper.getResourceSet(element);
- for (EClass eClassToCreateCommandsFor : eClassesToCreateCommandsFor) {
- // Use the resource set's registered factory, if possible (UML-RT)
- EObject newElement = getFactory(eClassToCreateCommandsFor, resourceSet).create(eClassToCreateCommandsFor);
- Command possibleCommand = editingDomainItemProvider.createCommand(element, getEditingDomain(), CreateChildCommand.class, new CommandParameter(element, containment, new CommandParameter(null, containment, newElement)));
- if (possibleCommand == null) {
- possibleCommands.add(UnexecutableCommand.INSTANCE);
- } else {
- if (possibleCommand.canExecute()) {
- possibleCommands.add(possibleCommand);
- }
- }
- }
- }
- }
- }
- return possibleCommands;
- }
-
- /**
- * Obtain the best factory for instantiation of the given {@code eClass}.
- * This is either
- * <ul>
- * <li>the factory registered locally in the {@code resourceSet} for the
- * {@code eClass}'s package, or</li>
- * <li>in the very unusual case that the package is not registered, or
- * if the {@code resourceSet} is {@code null}, the static factory
- * of the {@code eClass}'s static package</li>
- * </ul>
- *
- * @param eClass
- * an Ecore class to instantiate
- * @param resourceSet
- * the resource set in which context the model is being edited.
- * May be {@code null}
- *
- * @return the factory to use for instantiation of the {@code eClass}
- */
- EFactory getFactory(EClass eClass, ResourceSet resourceSet) {
- EFactory result = null;
-
- if (resourceSet != null) {
- result = resourceSet.getPackageRegistry().getEFactory(eClass.getEPackage().getNsURI());
- }
-
- if (result == null) {
- result = eClass.getEPackage().getEFactoryInstance();
- }
-
- return result;
- }
-
- /**
- * Prepares the EMF command to which we delegate execution, if
- * it has not already been created. This is not safe to do in a
- * read-only context if our request does not {@link CreateEditBasedElementCommand#hasElementToEdit() have
- * a container}, because this would attempt to create that
- * container.
- *
- * @see CreateEditBasedElementCommand#hasElementToEdit()
- */
- protected Command prepareCommand() {
- if (commandDone == null) {
- // Do the default element creation
- EReference containment = getContainmentFeature();
- EClass eClass = getElementType().getEClass();
- if (eClass.isAbstract()) {
- if (eClassHint == null) {
- // If we didn't receive a hint on the eClass to create
- // Propose to select appropriate concrete sub-metaclass
- try {
- ServicesRegistry registry = ServiceUtilsForResource.getInstance().getServiceRegistry(getElementToEdit().eResource());
- if (registry != null) {
- LabelProviderService labelProviderService = registry.getService(LabelProviderService.class);
- if (labelProviderService != null) {
- ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getCurrent().getActiveShell(), labelProviderService.getLabelProvider());
- dialog.setTitle("Metaclass selection");
- dialog.setMessage("Select the a concrete sub-metaclass of " + eClass.getName());
- dialog.setElements(EMFHelper.getSubclassesOf(eClass, true).toArray());
- dialog.setMultipleSelection(false);
- dialog.open();
- Object[] results = dialog.getResult();
- if (results != null) {
- if (results.length > 0) {
- if (results[0] instanceof EClass) {
- eClass = (EClass) results[0];
- }
- }
- }
- } else {
- Activator.log.error(new NullPointerException());
- commandDone = UnexecutableCommand.INSTANCE;
- }
- } else {
- Activator.log.error(new NullPointerException());
- commandDone = UnexecutableCommand.INSTANCE;
- }
- } catch (ServiceException e) {
- Activator.log.error(e);
- commandDone = UnexecutableCommand.INSTANCE;
- }
- } else {
- eClass = eClassHint;
- }
- }
- if (containment != null) {
- EObject element = getElementToEdit();
- if (element != null) {
- ResourceSet resourceSet = EMFHelper.getResourceSet(element);
- // Use the resource set's registered factory, if possible (UML-RT)
- newElement = getFactory(eClass, resourceSet).create(eClass);
- IEditingDomainItemProvider editingDomainItemProvider = AdapterFactoryEditingDomain.getEditingDomainItemProviderFor(element);
- commandDone = editingDomainItemProvider.createCommand(element, getEditingDomain(), CreateChildCommand.class, new CommandParameter(element, containment, new CommandParameter(null, containment, newElement)));
- }
- }
- if (commandDone == null) {
- // Couldn't create a useful command
- commandDone = UnexecutableCommand.INSTANCE;
- }
- }
- return commandDone;
- }
- }
-
- /** Shadow the base class's element-to-edit because we need direct access. */
- private EObject elementToEdit;
-
- /** newly created element */
- protected EObject newElement;
-
- /**
- * composite operation in charge of listing and executing all performed
- * operations
- */
- protected CompositeEMFOperation compositeEMFOperation;
-
- public static final String ECLASS_HINT = "ECLASS_HINT";
-
- protected EClass eClassHint = null;
-
- /**
- * Constructor.
- *
- * @param request
- * create element request creating this command
- */
- public CreateEditBasedElementCommand(CreateElementRequest request) {
- super(request);
- Object eClassHintParamValue = request.getParameter(ECLASS_HINT);
- if (eClassHintParamValue instanceof EClass) {
- eClassHint = (EClass) eClassHintParamValue;
- }
- EObject container = request.getContainer();
- if ((container != null) && container.eClass().getEAllContainments().contains(request.getContainmentFeature())) {
- setElementToEdit(container);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean canExecute() {
- // The superclass implementation can short-circuit the effort of
- // preparing the operation
- return super.canExecute() && prepareOperation().canExecute();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- IUndoableOperation operation = prepareOperation();
- IStatus compositeStatus = operation.execute(monitor, info);
- return (compositeStatus == null) ? CommandResult.newOKCommandResult(newElement) : new CommandResult(compositeStatus, newElement);
- }
-
- protected IUndoableOperation prepareOperation() {
- if (compositeEMFOperation == null) {
- compositeEMFOperation = new CompositeEMFOperation(getEditingDomain(), "Create Element");
- // creates the basic element
- AbstractTransactionalCommand createTransactionalCommand = new CreateEditBasedElementTransactionalCommand(getEditingDomain(), "Create basic element", getAffectedFiles());
- compositeEMFOperation.add(createTransactionalCommand);
- AbstractTransactionalCommand configureTransactionalCommand = new AbstractTransactionalCommand(getEditingDomain(), "Configure element", getAffectedFiles()) {
-
- /**
- * {@inheritDoc}ondre
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- // Configure the new element
- ConfigureRequest configureRequest = createConfigureRequest();
- ICommand configureCommand = getElementType().getEditCommand(configureRequest);
- IStatus configureStatus = null;
- if (configureCommand != null && configureCommand.canExecute()) {
- configureStatus = configureCommand.execute(monitor, info);
- }
- // Put the newly created element in the request so that the
- // 'after' commands have access to it.
- getCreateRequest().setNewElement(newElement);
- return (configureStatus == null) ? CommandResult.newOKCommandResult(newElement) : new CommandResult(configureStatus, newElement);
- }
- };
- compositeEMFOperation.add(configureTransactionalCommand);
- }
- return compositeEMFOperation;
- }
-
- protected boolean isPrepared() {
- return compositeEMFOperation != null;
- }
-
- /**
- * Creates the request to configure the new element.
- *
- * @return the request
- */
- @Override
- protected ConfigureRequest createConfigureRequest() {
- ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, getElementType());
- // pass along the client context
- configureRequest.setClientContext(getCreateRequest().getClientContext());
- configureRequest.addParameters(getRequest().getParameters());
- return configureRequest;
- }
-
- /**
- * Queries whether I know my element to edit, yet.
- *
- * @return whether I have an element to edit
- */
- protected boolean hasElementToEdit() {
- return elementToEdit != null;
- }
-
- @Override
- protected void setElementToEdit(EObject element) {
- this.elementToEdit = element;
- super.setElementToEdit(element);
- }
-
- /**
- * An enablement filter heuristically determining whether we think we will
- * be able to create the child element.
- *
- * @return whether we can create the new child element
- */
- protected boolean canCreateChild() {
- // Assume we can unless we think we can't
- boolean result = true;
- // This is an additional constraint in the EMF CreateChildCommand that
- // we use, that the GMF CreateElementCommand doesn't apply
- Object context = getRequest().getEditHelperContext();
- if (context instanceof EObject) {
- EObject owner = (EObject) context;
- EReference reference = getContainmentFeature();
- // The context may not have this reference if some intermediate
- // container is to be created by the edit-helper.
- // But, then, we can only optimistically report that we can create
- // the child
- if ((reference != null) && !reference.isMany() && (owner.eClass().getEAllReferences().contains(reference))) {
- // Don't replace an existing value
- result = ((EObject) context).eGet(reference) == null;
- }
- }
- return result;
- }
-
- @Override
- public void dispose() {
- if (isPrepared()) {
- compositeEMFOperation.dispose();
- compositeEMFOperation = null;
- }
- super.dispose();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013, 2016 CEA LIST, Christian W. Damus, 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 431109
+ * Christian W. Damus - bug 507618
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.command.UnexecutableCommand;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.emf.edit.command.CreateChildCommand;
+import org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain;
+import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.CompositeEMFOperation;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.commands.CreateElementCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateElementRequest;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForResource;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.services.labelprovider.service.LabelProviderService;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.dialogs.ElementListSelectionDialog;
+
+/**
+ * Creation command based on the metamodel.edit framework instead of relying on
+ * the defaut GMF creation mechanism.
+ * <P>
+ * So the creation of elements is similar to the creation customized in the metamodel itself, which can be interesting for metamodels like UML. This can avoid specific code for example for Activity.createNode() list of commands.
+ * </P>
+ * <P>
+ * The implementation relies on a composite command that delegates first the basic creation of the element to the metamodel.edit service.<BR/>
+ * A second operation computes during execution the list of additional commands to configure the newly created element. For example, the name of the new element can be set in configure commands. Note: the configure command needs the newly created command, so
+ * the list of operations to perform is unknown until the composite operation is executed. The executability of the 2nd set of commands can be hard to test.
+ * </P>
+ */
+public class CreateEditBasedElementCommand extends CreateElementCommand {
+
+ protected final class CreateEditBasedElementTransactionalCommand extends AbstractTransactionalCommand {
+ private Collection<Command> possibleCommands;
+ private Command commandDone;
+
+ protected CreateEditBasedElementTransactionalCommand(TransactionalEditingDomain domain, String label, List<?> affectedFiles) {
+ super(domain, label, affectedFiles);
+ }
+
+ @Override
+ public boolean canExecute() {
+ // Optimistically enable if the request would have to create
+ // the container, because
+ // we can't do that in a read-only context (when not
+ // actually executing)
+ return canCreateChild() && (!hasElementToEdit() || !(getPossibleCommands().isEmpty()));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ Command command = prepareCommand();
+ if (command.canExecute()) {
+ // create an IUndoableOperation => undo is relying on
+ // the execution of this command
+ command.execute();
+ return CommandResult.newOKCommandResult(newElement);
+ }
+ return CommandResult.newErrorCommandResult("Impossible to create Element");
+ }
+
+ protected Collection<Command> getPossibleCommands() {
+ if (possibleCommands == null) {
+ possibleCommands = new HashSet<Command>();
+ EClass eClass = getElementType().getEClass();
+ List<EClass> eClassesToCreateCommandsFor = new ArrayList<EClass>();
+ if (eClass.isAbstract()) {
+ // If we didn't receive a hint on the eClass to create
+ if (eClassHint == null) {
+ eClassesToCreateCommandsFor.addAll(EMFHelper.getSubclassesOf(eClass, true));
+ } else {
+ eClassesToCreateCommandsFor.add(eClassHint);
+ }
+ } else {
+ eClassesToCreateCommandsFor.add(eClass);
+ }
+ if (eClassesToCreateCommandsFor.isEmpty()) {
+ possibleCommands.add(UnexecutableCommand.INSTANCE);
+ }
+ EObject element = getElementToEdit();
+ if (element != null) {
+ // Do the default element creation
+ EReference containment = getContainmentFeature();
+ if (containment != null) {
+ IEditingDomainItemProvider editingDomainItemProvider = AdapterFactoryEditingDomain.getEditingDomainItemProviderFor(element);
+ ResourceSet resourceSet = EMFHelper.getResourceSet(element);
+ for (EClass eClassToCreateCommandsFor : eClassesToCreateCommandsFor) {
+ // Use the resource set's registered factory, if possible (UML-RT)
+ EObject newElement = getFactory(eClassToCreateCommandsFor, resourceSet).create(eClassToCreateCommandsFor);
+ Command possibleCommand = editingDomainItemProvider.createCommand(element, getEditingDomain(), CreateChildCommand.class, new CommandParameter(element, containment, new CommandParameter(null, containment, newElement)));
+ if (possibleCommand == null) {
+ possibleCommands.add(UnexecutableCommand.INSTANCE);
+ } else {
+ if (possibleCommand.canExecute()) {
+ possibleCommands.add(possibleCommand);
+ }
+ }
+ }
+ }
+ }
+ }
+ return possibleCommands;
+ }
+
+ /**
+ * Obtain the best factory for instantiation of the given {@code eClass}.
+ * This is either
+ * <ul>
+ * <li>the factory registered locally in the {@code resourceSet} for the
+ * {@code eClass}'s package, or</li>
+ * <li>in the very unusual case that the package is not registered, or
+ * if the {@code resourceSet} is {@code null}, the static factory
+ * of the {@code eClass}'s static package</li>
+ * </ul>
+ *
+ * @param eClass
+ * an Ecore class to instantiate
+ * @param resourceSet
+ * the resource set in which context the model is being edited.
+ * May be {@code null}
+ *
+ * @return the factory to use for instantiation of the {@code eClass}
+ */
+ EFactory getFactory(EClass eClass, ResourceSet resourceSet) {
+ EFactory result = null;
+
+ if (resourceSet != null) {
+ result = resourceSet.getPackageRegistry().getEFactory(eClass.getEPackage().getNsURI());
+ }
+
+ if (result == null) {
+ result = eClass.getEPackage().getEFactoryInstance();
+ }
+
+ return result;
+ }
+
+ /**
+ * Prepares the EMF command to which we delegate execution, if
+ * it has not already been created. This is not safe to do in a
+ * read-only context if our request does not {@link CreateEditBasedElementCommand#hasElementToEdit() have
+ * a container}, because this would attempt to create that
+ * container.
+ *
+ * @see CreateEditBasedElementCommand#hasElementToEdit()
+ */
+ protected Command prepareCommand() {
+ if (commandDone == null) {
+ // Do the default element creation
+ EReference containment = getContainmentFeature();
+ EClass eClass = getElementType().getEClass();
+ if (eClass.isAbstract()) {
+ if (eClassHint == null) {
+ // If we didn't receive a hint on the eClass to create
+ // Propose to select appropriate concrete sub-metaclass
+ try {
+ ServicesRegistry registry = ServiceUtilsForResource.getInstance().getServiceRegistry(getElementToEdit().eResource());
+ if (registry != null) {
+ LabelProviderService labelProviderService = registry.getService(LabelProviderService.class);
+ if (labelProviderService != null) {
+ ElementListSelectionDialog dialog = new ElementListSelectionDialog(Display.getCurrent().getActiveShell(), labelProviderService.getLabelProvider());
+ dialog.setTitle("Metaclass selection");
+ dialog.setMessage("Select the a concrete sub-metaclass of " + eClass.getName());
+ dialog.setElements(EMFHelper.getSubclassesOf(eClass, true).toArray());
+ dialog.setMultipleSelection(false);
+ dialog.open();
+ Object[] results = dialog.getResult();
+ if (results != null) {
+ if (results.length > 0) {
+ if (results[0] instanceof EClass) {
+ eClass = (EClass) results[0];
+ }
+ }
+ }
+ } else {
+ Activator.log.error(new NullPointerException());
+ commandDone = UnexecutableCommand.INSTANCE;
+ }
+ } else {
+ Activator.log.error(new NullPointerException());
+ commandDone = UnexecutableCommand.INSTANCE;
+ }
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ commandDone = UnexecutableCommand.INSTANCE;
+ }
+ } else {
+ eClass = eClassHint;
+ }
+ }
+ if (containment != null) {
+ EObject element = getElementToEdit();
+ if (element != null) {
+ ResourceSet resourceSet = EMFHelper.getResourceSet(element);
+ // Use the resource set's registered factory, if possible (UML-RT)
+ newElement = getFactory(eClass, resourceSet).create(eClass);
+ IEditingDomainItemProvider editingDomainItemProvider = AdapterFactoryEditingDomain.getEditingDomainItemProviderFor(element);
+ commandDone = editingDomainItemProvider.createCommand(element, getEditingDomain(), CreateChildCommand.class, new CommandParameter(element, containment, new CommandParameter(null, containment, newElement)));
+ }
+ }
+ if (commandDone == null) {
+ // Couldn't create a useful command
+ commandDone = UnexecutableCommand.INSTANCE;
+ }
+ }
+ return commandDone;
+ }
+ }
+
+ /** Shadow the base class's element-to-edit because we need direct access. */
+ private EObject elementToEdit;
+
+ /** newly created element */
+ protected EObject newElement;
+
+ /**
+ * composite operation in charge of listing and executing all performed
+ * operations
+ */
+ protected CompositeEMFOperation compositeEMFOperation;
+
+ public static final String ECLASS_HINT = "ECLASS_HINT";
+
+ protected EClass eClassHint = null;
+
+ /**
+ * Constructor.
+ *
+ * @param request
+ * create element request creating this command
+ */
+ public CreateEditBasedElementCommand(CreateElementRequest request) {
+ super(request);
+ Object eClassHintParamValue = request.getParameter(ECLASS_HINT);
+ if (eClassHintParamValue instanceof EClass) {
+ eClassHint = (EClass) eClassHintParamValue;
+ }
+ EObject container = request.getContainer();
+ if ((container != null) && container.eClass().getEAllContainments().contains(request.getContainmentFeature())) {
+ setElementToEdit(container);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean canExecute() {
+ // The superclass implementation can short-circuit the effort of
+ // preparing the operation
+ return super.canExecute() && prepareOperation().canExecute();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ IUndoableOperation operation = prepareOperation();
+ IStatus compositeStatus = operation.execute(monitor, info);
+ return (compositeStatus == null) ? CommandResult.newOKCommandResult(newElement) : new CommandResult(compositeStatus, newElement);
+ }
+
+ protected IUndoableOperation prepareOperation() {
+ if (compositeEMFOperation == null) {
+ compositeEMFOperation = new CompositeEMFOperation(getEditingDomain(), "Create Element");
+ // creates the basic element
+ AbstractTransactionalCommand createTransactionalCommand = new CreateEditBasedElementTransactionalCommand(getEditingDomain(), "Create basic element", getAffectedFiles());
+ compositeEMFOperation.add(createTransactionalCommand);
+ AbstractTransactionalCommand configureTransactionalCommand = new AbstractTransactionalCommand(getEditingDomain(), "Configure element", getAffectedFiles()) {
+
+ /**
+ * {@inheritDoc}ondre
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ // Configure the new element
+ ConfigureRequest configureRequest = createConfigureRequest();
+ ICommand configureCommand = getElementType().getEditCommand(configureRequest);
+ IStatus configureStatus = null;
+ if (configureCommand != null && configureCommand.canExecute()) {
+ configureStatus = configureCommand.execute(monitor, info);
+ }
+ // Put the newly created element in the request so that the
+ // 'after' commands have access to it.
+ getCreateRequest().setNewElement(newElement);
+ return (configureStatus == null) ? CommandResult.newOKCommandResult(newElement) : new CommandResult(configureStatus, newElement);
+ }
+ };
+ compositeEMFOperation.add(configureTransactionalCommand);
+ }
+ return compositeEMFOperation;
+ }
+
+ protected boolean isPrepared() {
+ return compositeEMFOperation != null;
+ }
+
+ /**
+ * Creates the request to configure the new element.
+ *
+ * @return the request
+ */
+ @Override
+ protected ConfigureRequest createConfigureRequest() {
+ ConfigureRequest configureRequest = new ConfigureRequest(getEditingDomain(), newElement, getElementType());
+ // pass along the client context
+ configureRequest.setClientContext(getCreateRequest().getClientContext());
+ configureRequest.addParameters(getRequest().getParameters());
+ return configureRequest;
+ }
+
+ /**
+ * Queries whether I know my element to edit, yet.
+ *
+ * @return whether I have an element to edit
+ */
+ protected boolean hasElementToEdit() {
+ return elementToEdit != null;
+ }
+
+ @Override
+ protected void setElementToEdit(EObject element) {
+ this.elementToEdit = element;
+ super.setElementToEdit(element);
+ }
+
+ /**
+ * An enablement filter heuristically determining whether we think we will
+ * be able to create the child element.
+ *
+ * @return whether we can create the new child element
+ */
+ protected boolean canCreateChild() {
+ // Assume we can unless we think we can't
+ boolean result = true;
+ // This is an additional constraint in the EMF CreateChildCommand that
+ // we use, that the GMF CreateElementCommand doesn't apply
+ Object context = getRequest().getEditHelperContext();
+ if (context instanceof EObject) {
+ EObject owner = (EObject) context;
+ EReference reference = getContainmentFeature();
+ // The context may not have this reference if some intermediate
+ // container is to be created by the edit-helper.
+ // But, then, we can only optimistically report that we can create
+ // the child
+ if ((reference != null) && !reference.isMany() && (owner.eClass().getEAllReferences().contains(reference))) {
+ // Don't replace an existing value
+ result = ((EObject) context).eGet(reference) == null;
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public void dispose() {
+ if (isPrepared()) {
+ compositeEMFOperation.dispose();
+ compositeEMFOperation = null;
+ }
+ super.dispose();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateShapeCompartmentViewCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateShapeCompartmentViewCommand.java
index ab0cfb5f4b8..20a04b9fa66 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateShapeCompartmentViewCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/CreateShapeCompartmentViewCommand.java
@@ -1,94 +1,94 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.TitleStyle;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.providers.ThemeInitializerManager;
-
-/**
- * Command to create the compartment displaying shapes for an element
- */
-public class CreateShapeCompartmentViewCommand extends RecordingCommand {
-
- /** owner of the compartment view to create */
- private View owner;
-
- /** booelan that indicates if the comaprtment has to be visible or not */
- private boolean isVisible;
-
- /**
- * Creates a new CreateShapeCompartmentViewCommand.
- *
- * @param domain
- * editing domain used to manipulate model
- * @param label
- * the label of the command
- * @param description
- * description of the command
- */
- public CreateShapeCompartmentViewCommand(TransactionalEditingDomain domain, String label, String description, View owner, boolean isVisible) {
- super(domain, label, description);
- this.owner = owner;
- this.setVisible(isVisible);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doExecute() {
- // FIXME should use here a view factory...
- Node compartment = NotationFactory.eINSTANCE.createBasicCompartment();
- compartment.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
- TitleStyle ts = NotationFactory.eINSTANCE.createTitleStyle();
-
- compartment.getStyles().add(ts);
- compartment.setType(IShapeCompartmentEditPart.VIEW_TYPE);
- ViewUtil.insertChildView(owner, compartment, ViewUtil.APPEND, false);
-
- // Bug 417178: The CSS Engine shall support compartments
- // Avoid preference-based or hard-coded initialization (CSS Compatibility)
- if (ThemeInitializerManager.instance.usePreferenceInitializer(compartment)) {
- ts.setShowTitle(false);
- compartment.setVisible(isVisible());
- compartment.setMutable(false);
- }
- }
-
- /**
- * Returns <code>true</code> if the created compartment should be visible
- *
- * @return <code>true</code> if the created compartment should be visible
- */
- public boolean isVisible() {
- return isVisible;
- }
-
- /**
- * Sets the visiblity of the created compartment
- *
- * @param isVisible
- * <code>true</code> if the compartment should be visible
- */
- public void setVisible(boolean isVisible) {
- this.isVisible = isVisible;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.TitleStyle;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.providers.ThemeInitializerManager;
+
+/**
+ * Command to create the compartment displaying shapes for an element
+ */
+public class CreateShapeCompartmentViewCommand extends RecordingCommand {
+
+ /** owner of the compartment view to create */
+ private View owner;
+
+ /** booelan that indicates if the comaprtment has to be visible or not */
+ private boolean isVisible;
+
+ /**
+ * Creates a new CreateShapeCompartmentViewCommand.
+ *
+ * @param domain
+ * editing domain used to manipulate model
+ * @param label
+ * the label of the command
+ * @param description
+ * description of the command
+ */
+ public CreateShapeCompartmentViewCommand(TransactionalEditingDomain domain, String label, String description, View owner, boolean isVisible) {
+ super(domain, label, description);
+ this.owner = owner;
+ this.setVisible(isVisible);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ // FIXME should use here a view factory...
+ Node compartment = NotationFactory.eINSTANCE.createBasicCompartment();
+ compartment.setLayoutConstraint(NotationFactory.eINSTANCE.createBounds());
+ TitleStyle ts = NotationFactory.eINSTANCE.createTitleStyle();
+
+ compartment.getStyles().add(ts);
+ compartment.setType(IShapeCompartmentEditPart.VIEW_TYPE);
+ ViewUtil.insertChildView(owner, compartment, ViewUtil.APPEND, false);
+
+ // Bug 417178: The CSS Engine shall support compartments
+ // Avoid preference-based or hard-coded initialization (CSS Compatibility)
+ if (ThemeInitializerManager.instance.usePreferenceInitializer(compartment)) {
+ ts.setShowTitle(false);
+ compartment.setVisible(isVisible());
+ compartment.setMutable(false);
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if the created compartment should be visible
+ *
+ * @return <code>true</code> if the created compartment should be visible
+ */
+ public boolean isVisible() {
+ return isVisible;
+ }
+
+ /**
+ * Sets the visiblity of the created compartment
+ *
+ * @param isVisible
+ * <code>true</code> if the compartment should be visible
+ */
+ public void setVisible(boolean isVisible) {
+ this.isVisible = isVisible;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultActionHandler.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultActionHandler.java
index 3a646a10a2c..b11f9ce8d00 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultActionHandler.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultActionHandler.java
@@ -1,27 +1,27 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.gef.commands.Command;
-
-/**
- * A Handler called when the user chooses a default action on
- * SelectAndExecuteCommand
- *
- * @author Camille Letavernier
- */
-public interface DefaultActionHandler {
-
- public void defaultActionSelected(Command defaultCommand);
-
- public String getLabel();
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.gef.commands.Command;
+
+/**
+ * A Handler called when the user chooses a default action on
+ * SelectAndExecuteCommand
+ *
+ * @author Camille Letavernier
+ */
+public interface DefaultActionHandler {
+
+ public void defaultActionSelected(Command defaultCommand);
+
+ public String getLabel();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
index db34d4a200f..8fca5b363a3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DefaultDiagramCopyCommand.java
@@ -1,124 +1,124 @@
-/*****************************************************************************
- * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, 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:
- * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
- * Christian W. Damus - bug 508404
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.emf.edit.command.AbstractOverrideableCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
-import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferencesPage;
-
-/**
- * Command that puts a list of object in the clipboard
- */
-public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand implements NonDirtying {
-
- /** list of objects to put in the clipboard */
- private final Collection<Object> objectsToPutInClipboard;
-
- public Collection<Object> getObjectsToPutInClipboard() {
- return objectsToPutInClipboard;
- }
-
- /** old list of the clipboard, for undo */
- private Collection<Object> oldClipboardContent;
-
- /**
- * Creates a new Command that set the new content of the clipboard
- *
- * @param domain
- * editing domain for which the clipboard is set.
- */
- public DefaultDiagramCopyCommand(EditingDomain domain, PapyrusClipboard<Object> papyrusClipboard, Collection<IGraphicalEditPart> pObjectsToPutInClipboard) {
- super(domain);
- objectsToPutInClipboard = new ArrayList<Object>();
- Boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES);
- EcoreUtil.Copier copier = ICopierFactory.getInstance(domain.getResourceSet(), keepReferences).get();
- List<EObject> objectToCopy = new ArrayList<EObject>();
-
- if (pObjectsToPutInClipboard != null) {
- for (IGraphicalEditPart iGraphicalEditPart : pObjectsToPutInClipboard) {
- View notationView = iGraphicalEditPart.getNotationView();
- EObject element = notationView.getElement();
- objectToCopy.add(notationView);
- objectToCopy.add(element);
- }
- }
-
- List<EObject> filterDescendants = EcoreUtil.filterDescendants(objectToCopy);
- copier.copyAll(filterDescendants);
- copier.copyReferences();
-
- Map<EObject, Object> mapInternalCopyInClipboard = new HashMap<EObject, Object>();
- mapInternalCopyInClipboard.putAll(copier);
- papyrusClipboard.addAllInternalCopyInClipboard(mapInternalCopyInClipboard);
-
-
- if (pObjectsToPutInClipboard != null && !pObjectsToPutInClipboard.isEmpty()) {
- IGraphicalEditPart next = pObjectsToPutInClipboard.iterator().next();
- Diagram diagram = next.getNotationView().getDiagram();
- if (diagram != null) {
- papyrusClipboard.setContainerType(diagram.getType());
- }
- }
-
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void doExecute() {
- oldClipboardContent = domain.getClipboard();
- domain.setClipboard(objectsToPutInClipboard);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void doUndo() {
- domain.setClipboard(oldClipboardContent);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void doRedo() {
- domain.setClipboard(objectsToPutInClipboard);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected boolean prepare() {
- return domain != null;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014, 2016 CEA LIST, Christian W. Damus, 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:
+ * Benoit Maggi (CEA LIST) benoit.maggi@cea.fr - Initial API and implementation
+ * Christian W. Damus - bug 508404
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.emf.common.command.AbstractCommand.NonDirtying;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.edit.command.AbstractOverrideableCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.clipboard.ICopierFactory;
+import org.eclipse.papyrus.infra.core.clipboard.PapyrusClipboard;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.preferences.PastePreferencesPage;
+
+/**
+ * Command that puts a list of object in the clipboard
+ */
+public class DefaultDiagramCopyCommand extends AbstractOverrideableCommand implements NonDirtying {
+
+ /** list of objects to put in the clipboard */
+ private final Collection<Object> objectsToPutInClipboard;
+
+ public Collection<Object> getObjectsToPutInClipboard() {
+ return objectsToPutInClipboard;
+ }
+
+ /** old list of the clipboard, for undo */
+ private Collection<Object> oldClipboardContent;
+
+ /**
+ * Creates a new Command that set the new content of the clipboard
+ *
+ * @param domain
+ * editing domain for which the clipboard is set.
+ */
+ public DefaultDiagramCopyCommand(EditingDomain domain, PapyrusClipboard<Object> papyrusClipboard, Collection<IGraphicalEditPart> pObjectsToPutInClipboard) {
+ super(domain);
+ objectsToPutInClipboard = new ArrayList<Object>();
+ Boolean keepReferences = Activator.getInstance().getPreferenceStore().getBoolean(PastePreferencesPage.KEEP_EXTERNAL_REFERENCES);
+ EcoreUtil.Copier copier = ICopierFactory.getInstance(domain.getResourceSet(), keepReferences).get();
+ List<EObject> objectToCopy = new ArrayList<EObject>();
+
+ if (pObjectsToPutInClipboard != null) {
+ for (IGraphicalEditPart iGraphicalEditPart : pObjectsToPutInClipboard) {
+ View notationView = iGraphicalEditPart.getNotationView();
+ EObject element = notationView.getElement();
+ objectToCopy.add(notationView);
+ objectToCopy.add(element);
+ }
+ }
+
+ List<EObject> filterDescendants = EcoreUtil.filterDescendants(objectToCopy);
+ copier.copyAll(filterDescendants);
+ copier.copyReferences();
+
+ Map<EObject, Object> mapInternalCopyInClipboard = new HashMap<EObject, Object>();
+ mapInternalCopyInClipboard.putAll(copier);
+ papyrusClipboard.addAllInternalCopyInClipboard(mapInternalCopyInClipboard);
+
+
+ if (pObjectsToPutInClipboard != null && !pObjectsToPutInClipboard.isEmpty()) {
+ IGraphicalEditPart next = pObjectsToPutInClipboard.iterator().next();
+ Diagram diagram = next.getNotationView().getDiagram();
+ if (diagram != null) {
+ papyrusClipboard.setContainerType(diagram.getType());
+ }
+ }
+
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doExecute() {
+ oldClipboardContent = domain.getClipboard();
+ domain.setClipboard(objectsToPutInClipboard);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doUndo() {
+ domain.setClipboard(oldClipboardContent);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void doRedo() {
+ domain.setClipboard(objectsToPutInClipboard);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected boolean prepare() {
+ return domain != null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DeferredSnapToGridCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DeferredSnapToGridCommand.java
index 05f52086dbb..0458ada2ba7 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DeferredSnapToGridCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/DeferredSnapToGridCommand.java
@@ -1,255 +1,255 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEALIST - Initial API and implementation (Adapted code from DeferredLayoutCommand)
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.emf.transaction.RunnableWithResult;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.SnapToHelper;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.snap.BorderNodeSnapHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.snap.NodeSnapHelper;
-
-/**
- * This command is used to snap editparts on the grid, when only the view
- * adapters are available at the time of creating the command. It is necessary
- * to have the editparts when creating a snap command so this command defers
- * the creation of the layout command until execution time at which point it can
- * get the editparts from the editpart registry using the view adapters.
- *
- * @author vlorenzo
- */
-// TODO : creation from the palette should use me
-// TODO : move action could use me???
-public class DeferredSnapToGridCommand extends AbstractTransactionalCommand {
-
- /** the IAdaptables from which an View can be retrieved */
- protected List<?> viewAdapters;
-
- /** the diagram editpart used to get the editpart registry */
- protected IGraphicalEditPart containerEP;
-
- /**
- * Constructor for <code>DefferedSnapToGridCommand</code>.
- *
- * @param editingDomain
- * the editing domain through which model changes are made
- * @param viewAdapters
- * the IAdaptables from which an IView can be retrieved
- * @param containerEP
- * the container editpart used to get the editpart registry
- */
- public DeferredSnapToGridCommand(TransactionalEditingDomain editingDomain, List<?> viewAdapters, IGraphicalEditPart containerEP) {
- super(editingDomain, "Deferred Snap to grid command", null); //$NON-NLS-1$
- this.viewAdapters = viewAdapters;
- this.containerEP = containerEP;
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
- *
- * @return
- */
- @Override
- @SuppressWarnings("rawtypes")
- public List getAffectedFiles() {
- if (containerEP != null) {
- View view = (View) containerEP.getModel();
- if (view != null) {
- IFile f = WorkspaceSynchronizer.getFile(view.eResource());
- return f != null ? Collections.singletonList(f) : Collections.EMPTY_LIST;
- }
- }
- return super.getAffectedFiles();
- }
-
- /**
- * Executes a layout command with all the editparts for the view adapters.
- *
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- final RunnableWithResult<List<IGraphicalEditPart>> refreshRunnable = new RunnableWithResult<List<IGraphicalEditPart>>() {
-
- private IStatus status;
-
- private List<IGraphicalEditPart> result;
-
- @Override
- public List<IGraphicalEditPart> getResult() {
- return result;
- }
-
- @Override
- public void setStatus(IStatus status) {
- this.status = status;
- }
-
- @Override
- public IStatus getStatus() {
- return status;
- }
-
- @Override
- public void run() {
- containerEP.refresh();
-
- // The layout command requires that the figure world is updated.
- getContainerFigure().invalidate();
- getContainerFigure().validate();
-
- List<IGraphicalEditPart> editParts = new ArrayList<IGraphicalEditPart>(viewAdapters.size());
- Map<?, ?> epRegistry = containerEP.getRoot().getViewer().getEditPartRegistry();
- for (Iterator<?> iter = viewAdapters.iterator(); iter.hasNext();) {
- IAdaptable ad = (IAdaptable) iter.next();
- View view = (View) ad.getAdapter(View.class);
- Object ep = epRegistry.get(view);
- if (ep instanceof IGraphicalEditPart) {
- editParts.add((IGraphicalEditPart) ep);
- }
- }
-
- if (editParts.isEmpty()) {
- result = editParts;
- return;
- }
-
- // probably useless
- // Set<IGraphicalEditPart> layoutSet = new HashSet<IGraphicalEditPart>(editParts.size());
- // layoutSet.addAll(editParts);
- //
- // // refresh source and target connections of any shapes in the container not being considered for layout
- // Iterator<?> iter = containerEP.getChildren().iterator();
- // while(iter.hasNext()) {
- // Object obj = iter.next();
- // if(!layoutSet.contains(obj) && obj instanceof IGraphicalEditPart) {
- // IGraphicalEditPart ep = (IGraphicalEditPart)obj;
- // ep.refresh();
- // }
- // }
-
- result = editParts;
- }
- };
-
- EditPartUtil.synchronizeRunnableToMainThread(containerEP, refreshRunnable);
- List<IGraphicalEditPart> editParts = refreshRunnable.getResult();
- if (editParts == null || editParts.isEmpty()) {
- return CommandResult.newOKCommandResult();
- }
-
- // add an arrange command, to layout the related shapes
- CompoundCommand cc = new CompoundCommand("Snap Command"); //$NON-NLS-1$
- for (final IGraphicalEditPart current : editParts) {
- final SnapToHelper snapHelper = (SnapToHelper) ((IAdaptable) current).getAdapter(SnapToHelper.class);
- final NodeSnapHelper nodeSnapHelper;
- final PrecisionRectangle boundsFigure = new PrecisionRectangle(((GraphicalEditPart) current).getFigure().getBounds());
- current.getFigure().translateToAbsolute(boundsFigure);
- final PrecisionRectangle result = new PrecisionRectangle(boundsFigure);
- if (current instanceof BorderedBorderItemEditPart) {
- nodeSnapHelper = new BorderNodeSnapHelper(snapHelper, boundsFigure);
- } else {
- nodeSnapHelper = new NodeSnapHelper(snapHelper, boundsFigure);
- }
- ChangeBoundsRequest request = new ChangeBoundsRequest("move"); //$NON-NLS-1$
- request.setEditParts(Collections.singletonList(current));
- request.setSnapToEnabled(true);
- request.setLocation(boundsFigure.getLocation());
- nodeSnapHelper.snapPoint(request);
- request.setLocation(result.getLocation());
- cc.add(((EditPart) current).getCommand(request));
- }
-
-
- if (!cc.isEmpty() && cc.canExecute()) {
- cc.execute();
- }
- return CommandResult.newOKCommandResult();
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
- *
- */
- @Override
- protected void cleanup() {
- containerEP = null;// for garbage collection
- viewAdapters = null;
- super.cleanup();
- }
-
- /**
- * gets the container edit part's figure
- *
- * @return the container figure
- */
- protected IFigure getContainerFigure() {
- return containerEP.getFigure();
- }
-
- /**
- * gets the container edit part
- *
- * @return the container edit part
- */
- protected IGraphicalEditPart getContainerEP() {
- return containerEP;
- }
-
- /**
- * gets a list of <code>IAdaptable</code> that can adapt to <code>
- * View</code>
- *
- * @return view adapters
- */
- protected List<?> getViewAdapters() {
- return viewAdapters;
- }
-
- /**
- *
- * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
- *
- * @return
- */
- @Override
- public boolean canExecute() {
- return super.canExecute() && containerEP != null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEALIST - Initial API and implementation (Adapted code from DeferredLayoutCommand)
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.emf.transaction.RunnableWithResult;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.SnapToHelper;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.BorderNodeSnapHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.NodeSnapHelper;
+
+/**
+ * This command is used to snap editparts on the grid, when only the view
+ * adapters are available at the time of creating the command. It is necessary
+ * to have the editparts when creating a snap command so this command defers
+ * the creation of the layout command until execution time at which point it can
+ * get the editparts from the editpart registry using the view adapters.
+ *
+ * @author vlorenzo
+ */
+// TODO : creation from the palette should use me
+// TODO : move action could use me???
+public class DeferredSnapToGridCommand extends AbstractTransactionalCommand {
+
+ /** the IAdaptables from which an View can be retrieved */
+ protected List<?> viewAdapters;
+
+ /** the diagram editpart used to get the editpart registry */
+ protected IGraphicalEditPart containerEP;
+
+ /**
+ * Constructor for <code>DefferedSnapToGridCommand</code>.
+ *
+ * @param editingDomain
+ * the editing domain through which model changes are made
+ * @param viewAdapters
+ * the IAdaptables from which an IView can be retrieved
+ * @param containerEP
+ * the container editpart used to get the editpart registry
+ */
+ public DeferredSnapToGridCommand(TransactionalEditingDomain editingDomain, List<?> viewAdapters, IGraphicalEditPart containerEP) {
+ super(editingDomain, "Deferred Snap to grid command", null); //$NON-NLS-1$
+ this.viewAdapters = viewAdapters;
+ this.containerEP = containerEP;
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#getAffectedFiles()
+ *
+ * @return
+ */
+ @Override
+ @SuppressWarnings("rawtypes")
+ public List getAffectedFiles() {
+ if (containerEP != null) {
+ View view = (View) containerEP.getModel();
+ if (view != null) {
+ IFile f = WorkspaceSynchronizer.getFile(view.eResource());
+ return f != null ? Collections.singletonList(f) : Collections.EMPTY_LIST;
+ }
+ }
+ return super.getAffectedFiles();
+ }
+
+ /**
+ * Executes a layout command with all the editparts for the view adapters.
+ *
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+ final RunnableWithResult<List<IGraphicalEditPart>> refreshRunnable = new RunnableWithResult<List<IGraphicalEditPart>>() {
+
+ private IStatus status;
+
+ private List<IGraphicalEditPart> result;
+
+ @Override
+ public List<IGraphicalEditPart> getResult() {
+ return result;
+ }
+
+ @Override
+ public void setStatus(IStatus status) {
+ this.status = status;
+ }
+
+ @Override
+ public IStatus getStatus() {
+ return status;
+ }
+
+ @Override
+ public void run() {
+ containerEP.refresh();
+
+ // The layout command requires that the figure world is updated.
+ getContainerFigure().invalidate();
+ getContainerFigure().validate();
+
+ List<IGraphicalEditPart> editParts = new ArrayList<IGraphicalEditPart>(viewAdapters.size());
+ Map<?, ?> epRegistry = containerEP.getRoot().getViewer().getEditPartRegistry();
+ for (Iterator<?> iter = viewAdapters.iterator(); iter.hasNext();) {
+ IAdaptable ad = (IAdaptable) iter.next();
+ View view = (View) ad.getAdapter(View.class);
+ Object ep = epRegistry.get(view);
+ if (ep instanceof IGraphicalEditPart) {
+ editParts.add((IGraphicalEditPart) ep);
+ }
+ }
+
+ if (editParts.isEmpty()) {
+ result = editParts;
+ return;
+ }
+
+ // probably useless
+ // Set<IGraphicalEditPart> layoutSet = new HashSet<IGraphicalEditPart>(editParts.size());
+ // layoutSet.addAll(editParts);
+ //
+ // // refresh source and target connections of any shapes in the container not being considered for layout
+ // Iterator<?> iter = containerEP.getChildren().iterator();
+ // while(iter.hasNext()) {
+ // Object obj = iter.next();
+ // if(!layoutSet.contains(obj) && obj instanceof IGraphicalEditPart) {
+ // IGraphicalEditPart ep = (IGraphicalEditPart)obj;
+ // ep.refresh();
+ // }
+ // }
+
+ result = editParts;
+ }
+ };
+
+ EditPartUtil.synchronizeRunnableToMainThread(containerEP, refreshRunnable);
+ List<IGraphicalEditPart> editParts = refreshRunnable.getResult();
+ if (editParts == null || editParts.isEmpty()) {
+ return CommandResult.newOKCommandResult();
+ }
+
+ // add an arrange command, to layout the related shapes
+ CompoundCommand cc = new CompoundCommand("Snap Command"); //$NON-NLS-1$
+ for (final IGraphicalEditPart current : editParts) {
+ final SnapToHelper snapHelper = (SnapToHelper) ((IAdaptable) current).getAdapter(SnapToHelper.class);
+ final NodeSnapHelper nodeSnapHelper;
+ final PrecisionRectangle boundsFigure = new PrecisionRectangle(((GraphicalEditPart) current).getFigure().getBounds());
+ current.getFigure().translateToAbsolute(boundsFigure);
+ final PrecisionRectangle result = new PrecisionRectangle(boundsFigure);
+ if (current instanceof BorderedBorderItemEditPart) {
+ nodeSnapHelper = new BorderNodeSnapHelper(snapHelper, boundsFigure);
+ } else {
+ nodeSnapHelper = new NodeSnapHelper(snapHelper, boundsFigure);
+ }
+ ChangeBoundsRequest request = new ChangeBoundsRequest("move"); //$NON-NLS-1$
+ request.setEditParts(Collections.singletonList(current));
+ request.setSnapToEnabled(true);
+ request.setLocation(boundsFigure.getLocation());
+ nodeSnapHelper.snapPoint(request);
+ request.setLocation(result.getLocation());
+ cc.add(((EditPart) current).getCommand(request));
+ }
+
+
+ if (!cc.isEmpty() && cc.canExecute()) {
+ cc.execute();
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
+ *
+ */
+ @Override
+ protected void cleanup() {
+ containerEP = null;// for garbage collection
+ viewAdapters = null;
+ super.cleanup();
+ }
+
+ /**
+ * gets the container edit part's figure
+ *
+ * @return the container figure
+ */
+ protected IFigure getContainerFigure() {
+ return containerEP.getFigure();
+ }
+
+ /**
+ * gets the container edit part
+ *
+ * @return the container edit part
+ */
+ protected IGraphicalEditPart getContainerEP() {
+ return containerEP;
+ }
+
+ /**
+ * gets a list of <code>IAdaptable</code> that can adapt to <code>
+ * View</code>
+ *
+ * @return view adapters
+ */
+ protected List<?> getViewAdapters() {
+ return viewAdapters;
+ }
+
+ /**
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && containerEP != null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java
index 87a54180de3..08d510738cb 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorAfterCreationCommand.java
@@ -1,159 +1,159 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.IdentityAnchor;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.geometry.RectangleUtils;
-import org.eclipse.papyrus.infra.gmfdiag.common.geometry.Segment;
-import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
-
-
-/**
- *
- * This command is used to fix the edge anchor just after the creation of the edge, in order to get anchor on the sides of the source
- * and target figure and not somewhere inside the figure.
- *
- * This fix allows to avoid to get source (or target) location moving instead you are moving the target (or source) anchor
- *
- * see bug 430702: [Diagram] Moving source of a link moves the target too.
- */
-
-public class FixEdgeAnchorAfterCreationCommand extends AbstractTransactionalCommand {
-
- private static final String RECT_RIGHT_MIDDLE_ANCHOR = "(1.0,0.5)";
-
- private static final String RECT_BOTTOM_MIDDLE_ANCHOR = "(0.5,1.0)";
-
- /**
- * the request used to create connection view
- */
- protected CreateConnectionViewRequest request;
-
- /**
- *
- * Constructor.
- *
- * @param editingDomain
- * the editing domain
- * @param request
- * the creation request
- * @param containerEP
- * the diagram edit part
- */
- public FixEdgeAnchorAfterCreationCommand(final TransactionalEditingDomain editingDomain, final CreateConnectionViewRequest request) {
- super(editingDomain, "Fix Edge Anchor after creation", null); //$NON-NLS-1$
- this.request = request;
- }
-
-
- /**
- * Executes a fix anchor command for the created edge
- *
- */
- @Override
- protected CommandResult doExecuteWithResult(final IProgressMonitor progressMonitor, final IAdaptable info) throws ExecutionException {
- final ConnectionViewDescriptor connectionViewDescriptor = this.request.getConnectionViewDescriptor();
- final Edge createdEdge = (Edge) connectionViewDescriptor.getAdapter(View.class);
- final IAdaptable adaptable = connectionViewDescriptor.getElementAdapter();
- final CreateRelationshipRequest createRelationShipRequest = (CreateRelationshipRequest) adaptable.getAdapter(CreateRelationshipRequest.class);
- final Map<?, ?> requestParameters = createRelationShipRequest.getParameters();
- final IFigure sourceFigure = (IFigure) requestParameters.get(RequestParameterConstants.EDGE_SOURCE_FIGURE);
- final IFigure targetFigure = (IFigure) requestParameters.get(RequestParameterConstants.EDGE_TARGET_FIGURE);
- final Point sourcePoint = (Point) requestParameters.get(RequestParameterConstants.EDGE_SOURCE_POINT);
- final Point targetPoint = (Point) requestParameters.get(RequestParameterConstants.EDGE_TARGET_POINT);
- if (createdEdge != null && sourceFigure instanceof IAnchorableFigure && targetFigure instanceof IAnchorableFigure && sourcePoint != null && targetPoint != null) {
- final String sourceTerminal;
- final String targetTerminal;
- if (sourceFigure == targetFigure) {
- sourceTerminal = RECT_RIGHT_MIDDLE_ANCHOR.toString();
- targetTerminal = RECT_BOTTOM_MIDDLE_ANCHOR.toString();
- } else {
-
- final Rectangle sourceBds = sourceFigure.getBounds().getCopy();
- final Rectangle targetBds = targetFigure.getBounds().getCopy();
- sourceFigure.translateToAbsolute(sourceBds);
- targetFigure.translateToAbsolute(targetBds);
-
- final Segment segment = new Segment(sourcePoint, targetPoint);
- final Point realSourcePoint = RectangleUtils.getIntersectionPoint(sourceBds, segment);
- final Point realTargetPoint = RectangleUtils.getIntersectionPoint(targetBds, segment);
-
- // get source anchor terminal
- final BaseSlidableAnchor anchorSource = (BaseSlidableAnchor) ((IAnchorableFigure) sourceFigure).getSourceConnectionAnchorAt(realSourcePoint);
- sourceTerminal = anchorSource.getTerminal();
-
- // get target anchor terminal
- final BaseSlidableAnchor anchorTarget = (BaseSlidableAnchor) ((IAnchorableFigure) targetFigure).getTargetConnectionAnchorAt(realTargetPoint);
- targetTerminal = anchorTarget.getTerminal();
- // create and set the source anchor
- }
- // TODO : it is possible that the result will be not correct when the preferred routing for the link is not the oblique router
- final IdentityAnchor sourceAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
- sourceAnchor.setId(sourceTerminal);
- createdEdge.setSourceAnchor(sourceAnchor);
-
- // create an set the target anchor
- final IdentityAnchor targetAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
- targetAnchor.setId(targetTerminal);
- createdEdge.setTargetAnchor(targetAnchor);
-
- return CommandResult.newOKCommandResult();
- }
- return CommandResult.newOKCommandResult();
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
- *
- */
- @Override
- protected void cleanup() {
- this.request = null;
- super.cleanup();
- }
-
-
- /**
- *
- * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
- *
- * @return
- */
- @Override
- public boolean canExecute() {
- return super.canExecute() && this.request != null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateConnectionViewRequest.ConnectionViewDescriptor;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.CreateRelationshipRequest;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.geometry.RectangleUtils;
+import org.eclipse.papyrus.infra.gmfdiag.common.geometry.Segment;
+import org.eclipse.papyrus.infra.services.edit.utils.RequestParameterConstants;
+
+
+/**
+ *
+ * This command is used to fix the edge anchor just after the creation of the edge, in order to get anchor on the sides of the source
+ * and target figure and not somewhere inside the figure.
+ *
+ * This fix allows to avoid to get source (or target) location moving instead you are moving the target (or source) anchor
+ *
+ * see bug 430702: [Diagram] Moving source of a link moves the target too.
+ */
+
+public class FixEdgeAnchorAfterCreationCommand extends AbstractTransactionalCommand {
+
+ private static final String RECT_RIGHT_MIDDLE_ANCHOR = "(1.0,0.5)";
+
+ private static final String RECT_BOTTOM_MIDDLE_ANCHOR = "(0.5,1.0)";
+
+ /**
+ * the request used to create connection view
+ */
+ protected CreateConnectionViewRequest request;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param request
+ * the creation request
+ * @param containerEP
+ * the diagram edit part
+ */
+ public FixEdgeAnchorAfterCreationCommand(final TransactionalEditingDomain editingDomain, final CreateConnectionViewRequest request) {
+ super(editingDomain, "Fix Edge Anchor after creation", null); //$NON-NLS-1$
+ this.request = request;
+ }
+
+
+ /**
+ * Executes a fix anchor command for the created edge
+ *
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(final IProgressMonitor progressMonitor, final IAdaptable info) throws ExecutionException {
+ final ConnectionViewDescriptor connectionViewDescriptor = this.request.getConnectionViewDescriptor();
+ final Edge createdEdge = (Edge) connectionViewDescriptor.getAdapter(View.class);
+ final IAdaptable adaptable = connectionViewDescriptor.getElementAdapter();
+ final CreateRelationshipRequest createRelationShipRequest = (CreateRelationshipRequest) adaptable.getAdapter(CreateRelationshipRequest.class);
+ final Map<?, ?> requestParameters = createRelationShipRequest.getParameters();
+ final IFigure sourceFigure = (IFigure) requestParameters.get(RequestParameterConstants.EDGE_SOURCE_FIGURE);
+ final IFigure targetFigure = (IFigure) requestParameters.get(RequestParameterConstants.EDGE_TARGET_FIGURE);
+ final Point sourcePoint = (Point) requestParameters.get(RequestParameterConstants.EDGE_SOURCE_POINT);
+ final Point targetPoint = (Point) requestParameters.get(RequestParameterConstants.EDGE_TARGET_POINT);
+ if (createdEdge != null && sourceFigure instanceof IAnchorableFigure && targetFigure instanceof IAnchorableFigure && sourcePoint != null && targetPoint != null) {
+ final String sourceTerminal;
+ final String targetTerminal;
+ if (sourceFigure == targetFigure) {
+ sourceTerminal = RECT_RIGHT_MIDDLE_ANCHOR.toString();
+ targetTerminal = RECT_BOTTOM_MIDDLE_ANCHOR.toString();
+ } else {
+
+ final Rectangle sourceBds = sourceFigure.getBounds().getCopy();
+ final Rectangle targetBds = targetFigure.getBounds().getCopy();
+ sourceFigure.translateToAbsolute(sourceBds);
+ targetFigure.translateToAbsolute(targetBds);
+
+ final Segment segment = new Segment(sourcePoint, targetPoint);
+ final Point realSourcePoint = RectangleUtils.getIntersectionPoint(sourceBds, segment);
+ final Point realTargetPoint = RectangleUtils.getIntersectionPoint(targetBds, segment);
+
+ // get source anchor terminal
+ final BaseSlidableAnchor anchorSource = (BaseSlidableAnchor) ((IAnchorableFigure) sourceFigure).getSourceConnectionAnchorAt(realSourcePoint);
+ sourceTerminal = anchorSource.getTerminal();
+
+ // get target anchor terminal
+ final BaseSlidableAnchor anchorTarget = (BaseSlidableAnchor) ((IAnchorableFigure) targetFigure).getTargetConnectionAnchorAt(realTargetPoint);
+ targetTerminal = anchorTarget.getTerminal();
+ // create and set the source anchor
+ }
+ // TODO : it is possible that the result will be not correct when the preferred routing for the link is not the oblique router
+ final IdentityAnchor sourceAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ sourceAnchor.setId(sourceTerminal);
+ createdEdge.setSourceAnchor(sourceAnchor);
+
+ // create an set the target anchor
+ final IdentityAnchor targetAnchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ targetAnchor.setId(targetTerminal);
+ createdEdge.setTargetAnchor(targetAnchor);
+
+ return CommandResult.newOKCommandResult();
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
+ *
+ */
+ @Override
+ protected void cleanup() {
+ this.request = null;
+ super.cleanup();
+ }
+
+
+ /**
+ *
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canExecute()
+ *
+ * @return
+ */
+ @Override
+ public boolean canExecute() {
+ return super.canExecute() && this.request != null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java
index 0554c1740d3..35b3373defa 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/FixEdgeAnchorsDeferredCommand.java
@@ -1,148 +1,148 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-
-/**
- *
- * see bug 430702: [Diagram] Moving source of a link moves the target too.
- *
- * This class allows to fix the anchors for a collection of connection edit part
- *
- */
-public class FixEdgeAnchorsDeferredCommand extends AbstractFixEdgeAnchorDeferredCommand {
-
- /**
- * the list of the connections to refresh
- */
- private Collection<?> connectionsEditPartToRefresh;
-
- /**
- *
- * Constructor.
- *
- * @param editingDomain
- * the editing domain
- * @param request
- * the creation request
- * @param containerEP
- * the diagram edit part
- */
- public FixEdgeAnchorsDeferredCommand(final TransactionalEditingDomain editingDomain, final IGraphicalEditPart containerEP, final Collection<?> connectionsEditPartToRefresh) {
- super(editingDomain, "Fix Edge Anchors", containerEP); //$NON-NLS-1$
- this.connectionsEditPartToRefresh = new ArrayList<Object>(connectionsEditPartToRefresh);
- }
-
-
- /**
- * Executes a fix anchor command for the created edge
- *
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- final RefreshConnectionElementsRunnable refreshRunnable = new RefreshConnectionElementsRunnable(this.connectionsEditPartToRefresh, getContainerEP());
-
- EditPartUtil.synchronizeRunnableToMainThread(getContainerEP(), refreshRunnable);
- final Collection<AbstractConnectionEditPart> toRefresh = refreshRunnable.getResult();
- final Iterator<AbstractConnectionEditPart> iter = toRefresh.iterator();
- while (iter.hasNext()) {
- final CompoundCommand cc = new CompoundCommand("Fix connections anchors"); //$NON-NLS-1$
- final AbstractConnectionEditPart current = iter.next();
- addFixAnchorCommand(current, cc);
- if (cc.canExecute()) {
- cc.execute();
- } else {
- Activator.log.warn("Command to fix the anchors is null"); //$NON-NLS-1$
- }
- }
- return CommandResult.newOKCommandResult();
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
- *
- */
- @Override
- protected void cleanup() {
- super.cleanup();
- this.connectionsEditPartToRefresh.clear();
- }
-
- private static class RefreshConnectionElementsRunnable extends AbstractRefreshConnectionElementsRunnable<Collection<AbstractConnectionEditPart>> {
-
- /**
- * the list of the connections to refresh
- */
- private Collection<?> connectionsEditPartToRefresh;
-
- /**
- *
- * Constructor.
- *
- * @param connectionsEditPartToRefresh
- * the list of the connection edit part to refresh
- * @param containerEP
- */
- public RefreshConnectionElementsRunnable(final Collection<?> connectionsEditPartToRefresh, final IGraphicalEditPart containerEP) {
- super(containerEP);
- this.connectionsEditPartToRefresh = connectionsEditPartToRefresh;
- }
-
- /**
- *
- * @see java.lang.Runnable#run()
- *
- */
- @Override
- public void run() {
- getContainerEditPart().refresh();
-
- // We update the figure world
- getContainerFigure().invalidate();
- getContainerFigure().validate();
- final Iterator<?> iter = connectionsEditPartToRefresh.iterator();
- final Collection<AbstractConnectionEditPart> connectionsEP = new HashSet<AbstractConnectionEditPart>();
- setResult(connectionsEP);
- while (iter.hasNext()) {
- final Object object = iter.next();
- if (object instanceof AbstractConnectionEditPart) {
- connectionsEP.add((AbstractConnectionEditPart) object);
- refreshConnection((AbstractConnectionEditPart) object);
- }
- }
- setStatus(Status.OK_STATUS);
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.util.EditPartUtil;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+
+/**
+ *
+ * see bug 430702: [Diagram] Moving source of a link moves the target too.
+ *
+ * This class allows to fix the anchors for a collection of connection edit part
+ *
+ */
+public class FixEdgeAnchorsDeferredCommand extends AbstractFixEdgeAnchorDeferredCommand {
+
+ /**
+ * the list of the connections to refresh
+ */
+ private Collection<?> connectionsEditPartToRefresh;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param editingDomain
+ * the editing domain
+ * @param request
+ * the creation request
+ * @param containerEP
+ * the diagram edit part
+ */
+ public FixEdgeAnchorsDeferredCommand(final TransactionalEditingDomain editingDomain, final IGraphicalEditPart containerEP, final Collection<?> connectionsEditPartToRefresh) {
+ super(editingDomain, "Fix Edge Anchors", containerEP); //$NON-NLS-1$
+ this.connectionsEditPartToRefresh = new ArrayList<Object>(connectionsEditPartToRefresh);
+ }
+
+
+ /**
+ * Executes a fix anchor command for the created edge
+ *
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+ final RefreshConnectionElementsRunnable refreshRunnable = new RefreshConnectionElementsRunnable(this.connectionsEditPartToRefresh, getContainerEP());
+
+ EditPartUtil.synchronizeRunnableToMainThread(getContainerEP(), refreshRunnable);
+ final Collection<AbstractConnectionEditPart> toRefresh = refreshRunnable.getResult();
+ final Iterator<AbstractConnectionEditPart> iter = toRefresh.iterator();
+ while (iter.hasNext()) {
+ final CompoundCommand cc = new CompoundCommand("Fix connections anchors"); //$NON-NLS-1$
+ final AbstractConnectionEditPart current = iter.next();
+ addFixAnchorCommand(current, cc);
+ if (cc.canExecute()) {
+ cc.execute();
+ } else {
+ Activator.log.warn("Command to fix the anchors is null"); //$NON-NLS-1$
+ }
+ }
+ return CommandResult.newOKCommandResult();
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand#cleanup()
+ *
+ */
+ @Override
+ protected void cleanup() {
+ super.cleanup();
+ this.connectionsEditPartToRefresh.clear();
+ }
+
+ private static class RefreshConnectionElementsRunnable extends AbstractRefreshConnectionElementsRunnable<Collection<AbstractConnectionEditPart>> {
+
+ /**
+ * the list of the connections to refresh
+ */
+ private Collection<?> connectionsEditPartToRefresh;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param connectionsEditPartToRefresh
+ * the list of the connection edit part to refresh
+ * @param containerEP
+ */
+ public RefreshConnectionElementsRunnable(final Collection<?> connectionsEditPartToRefresh, final IGraphicalEditPart containerEP) {
+ super(containerEP);
+ this.connectionsEditPartToRefresh = connectionsEditPartToRefresh;
+ }
+
+ /**
+ *
+ * @see java.lang.Runnable#run()
+ *
+ */
+ @Override
+ public void run() {
+ getContainerEditPart().refresh();
+
+ // We update the figure world
+ getContainerFigure().invalidate();
+ getContainerFigure().validate();
+ final Iterator<?> iter = connectionsEditPartToRefresh.iterator();
+ final Collection<AbstractConnectionEditPart> connectionsEP = new HashSet<AbstractConnectionEditPart>();
+ setResult(connectionsEP);
+ while (iter.hasNext()) {
+ final Object object = iter.next();
+ if (object instanceof AbstractConnectionEditPart) {
+ connectionsEP.add((AbstractConnectionEditPart) object);
+ refreshConnection((AbstractConnectionEditPart) object);
+ }
+ }
+ setStatus(Status.OK_STATUS);
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/ISemanticHintAdapter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/ISemanticHintAdapter.java
index 040fbd2f230..eed6879d175 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/ISemanticHintAdapter.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/ISemanticHintAdapter.java
@@ -1,28 +1,28 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-
-/**
- * Interface for an adapter that can give a semantic hint
- */
-public interface ISemanticHintAdapter {
-
- /**
- * Returns the semantic hint for this adapter
- *
- * @return the semantic hint for this adapter
- */
- public String getSemanticHint();
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+
+/**
+ * Interface for an adapter that can give a semantic hint
+ */
+public interface ISemanticHintAdapter {
+
+ /**
+ * Returns the semantic hint for this adapter
+ *
+ * @return the semantic hint for this adapter
+ */
+ public String getSemanticHint();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertFloatingLabelFromMapCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertFloatingLabelFromMapCommand.java
index 7a8a4c9a516..4e84236b395 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertFloatingLabelFromMapCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/InsertFloatingLabelFromMapCommand.java
@@ -1,167 +1,167 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2015 CEA LIST 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:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.Map;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.notation.DecorationNode;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Location;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * The Class InsertFloatingLabelFromMapCommand. Used with reconciler to insert to views's diagram corresponding to the key a child corresponding to the value.
- * If a child having the same type already exist, it is not added.
- */
-public class InsertFloatingLabelFromMapCommand extends AbstractCommand {
-
-
- /** The diagram. */
- private Diagram diagram;
-
- /** The floating labels map. */
- private Map<String, String> floatingLabelsMap;
-
- /**
- * Instantiates a new InsertFloatingLabelFromMapCommand command.
- *
- * @param diagram
- * the diagram
- * @param floatingLabelMap
- * the floating label map
- */
- public InsertFloatingLabelFromMapCommand(Diagram diagram, Map<String, String> floatingLabelMap) {
- super("Migrate Class Diagram");
- this.diagram = diagram;
- this.floatingLabelsMap = floatingLabelMap;
- }
-
- /**
- * Do execute with result.
- *
- * @param progressMonitor
- * the progress monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.common.core.command.AbstractCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- // EObject element = diagram.getElement();
-
- final TreeIterator<EObject> children = diagram.eAllContents();
-
- while (children.hasNext()) {
- EObject object = (EObject) children.next();
- // for (Object child : children) {
- if (object instanceof View) {
- View element = (View) object;
-
- // foatingLabel have to be adds to the Element
- if (floatingLabelsMap.containsKey(element.getType())) {
-
- String floatingLabelVisualId = floatingLabelsMap.get(element.getType());
-
- // If it doesn't exist yet
- boolean haveFloatingLabel = false;
- for (Object child : element.getChildren()) {
- if (child instanceof View) {
- if (floatingLabelVisualId.equals(((View) child).getType())) {
- haveFloatingLabel = true;
- }
- }
- }
- if (!haveFloatingLabel) {
- // Create the decoration node corresponding to the floating label
- DecorationNode floatingLabel = NotationFactory.eINSTANCE.createDecorationNode();
- floatingLabel.setType(floatingLabelVisualId);
- final Location location = NotationFactory.eINSTANCE.createLocation();
- location.setY(5);
- floatingLabel.setLayoutConstraint(location);
- element.insertChild(floatingLabel);
- }
- }
- }
- }
-
- return CommandResult.newOKCommandResult();
- }
-
-
- /**
- * Can undo.
- *
- * @return true, if successful
- * @see org.eclipse.core.commands.operations.AbstractOperation#canUndo()
- */
- @Override
- public boolean canUndo() {
- return false;
- }
-
- /**
- * Can redo.
- *
- * @return true, if successful
- * @see org.eclipse.core.commands.operations.AbstractOperation#canRedo()
- */
- @Override
- public boolean canRedo() {
- return false;
- }
-
- /**
- * Do redo with result.
- *
- * @param progressMonitor
- * the progress monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.common.core.command.AbstractCommand#doRedoWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- throw new ExecutionException("Should not be called, canRedo false");
- }
-
- /**
- * Do undo with result.
- *
- * @param progressMonitor
- * the progress monitor
- * @param info
- * the info
- * @return the command result
- * @throws ExecutionException
- * the execution exception
- * @see org.eclipse.gmf.runtime.common.core.command.AbstractCommand#doUndoWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
- */
- @Override
- protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
- throw new ExecutionException("Should not be called, canUndo false");
- }
+/*****************************************************************************
+ * Copyright (c) 2010, 2015 CEA LIST 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.Map;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.command.AbstractCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.notation.DecorationNode;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Location;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * The Class InsertFloatingLabelFromMapCommand. Used with reconciler to insert to views's diagram corresponding to the key a child corresponding to the value.
+ * If a child having the same type already exist, it is not added.
+ */
+public class InsertFloatingLabelFromMapCommand extends AbstractCommand {
+
+
+ /** The diagram. */
+ private Diagram diagram;
+
+ /** The floating labels map. */
+ private Map<String, String> floatingLabelsMap;
+
+ /**
+ * Instantiates a new InsertFloatingLabelFromMapCommand command.
+ *
+ * @param diagram
+ * the diagram
+ * @param floatingLabelMap
+ * the floating label map
+ */
+ public InsertFloatingLabelFromMapCommand(Diagram diagram, Map<String, String> floatingLabelMap) {
+ super("Migrate Class Diagram");
+ this.diagram = diagram;
+ this.floatingLabelsMap = floatingLabelMap;
+ }
+
+ /**
+ * Do execute with result.
+ *
+ * @param progressMonitor
+ * the progress monitor
+ * @param info
+ * the info
+ * @return the command result
+ * @throws ExecutionException
+ * the execution exception
+ * @see org.eclipse.gmf.runtime.common.core.command.AbstractCommand#doExecuteWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ // EObject element = diagram.getElement();
+
+ final TreeIterator<EObject> children = diagram.eAllContents();
+
+ while (children.hasNext()) {
+ EObject object = (EObject) children.next();
+ // for (Object child : children) {
+ if (object instanceof View) {
+ View element = (View) object;
+
+ // foatingLabel have to be adds to the Element
+ if (floatingLabelsMap.containsKey(element.getType())) {
+
+ String floatingLabelVisualId = floatingLabelsMap.get(element.getType());
+
+ // If it doesn't exist yet
+ boolean haveFloatingLabel = false;
+ for (Object child : element.getChildren()) {
+ if (child instanceof View) {
+ if (floatingLabelVisualId.equals(((View) child).getType())) {
+ haveFloatingLabel = true;
+ }
+ }
+ }
+ if (!haveFloatingLabel) {
+ // Create the decoration node corresponding to the floating label
+ DecorationNode floatingLabel = NotationFactory.eINSTANCE.createDecorationNode();
+ floatingLabel.setType(floatingLabelVisualId);
+ final Location location = NotationFactory.eINSTANCE.createLocation();
+ location.setY(5);
+ floatingLabel.setLayoutConstraint(location);
+ element.insertChild(floatingLabel);
+ }
+ }
+ }
+ }
+
+ return CommandResult.newOKCommandResult();
+ }
+
+
+ /**
+ * Can undo.
+ *
+ * @return true, if successful
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canUndo()
+ */
+ @Override
+ public boolean canUndo() {
+ return false;
+ }
+
+ /**
+ * Can redo.
+ *
+ * @return true, if successful
+ * @see org.eclipse.core.commands.operations.AbstractOperation#canRedo()
+ */
+ @Override
+ public boolean canRedo() {
+ return false;
+ }
+
+ /**
+ * Do redo with result.
+ *
+ * @param progressMonitor
+ * the progress monitor
+ * @param info
+ * the info
+ * @return the command result
+ * @throws ExecutionException
+ * the execution exception
+ * @see org.eclipse.gmf.runtime.common.core.command.AbstractCommand#doRedoWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ throw new ExecutionException("Should not be called, canRedo false");
+ }
+
+ /**
+ * Do undo with result.
+ *
+ * @param progressMonitor
+ * the progress monitor
+ * @param info
+ * the info
+ * @return the command result
+ * @throws ExecutionException
+ * the execution exception
+ * @see org.eclipse.gmf.runtime.common.core.command.AbstractCommand#doUndoWithResult(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)
+ */
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+ throw new ExecutionException("Should not be called, canUndo false");
+ }
} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForDo.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForDo.java
index 3edebbb93a2..9947611b544 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForDo.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForDo.java
@@ -1,35 +1,35 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.gef.GraphicalEditPart;
-
-/**
- * Refresh the {@link IFigure} of a given {@link GraphicalEditPart} on execute and redo of this command. This command
- * must be placed at the end of a {@link CompoundCommand}, as the execute and redo are done in forward order.
- * @since 3.0
- */
-public class RefreshCommandForDo extends AbstractRefreshCommand {
-
- public RefreshCommandForDo(final GraphicalEditPart editPartToRefresh) {
- super(editPartToRefresh);
- }
-
- @Override
- public void execute() {
- refresh();
- }
-
- @Override
- public void redo() {
- refresh();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.gef.GraphicalEditPart;
+
+/**
+ * Refresh the {@link IFigure} of a given {@link GraphicalEditPart} on execute and redo of this command. This command
+ * must be placed at the end of a {@link CompoundCommand}, as the execute and redo are done in forward order.
+ * @since 3.0
+ */
+public class RefreshCommandForDo extends AbstractRefreshCommand {
+
+ public RefreshCommandForDo(final GraphicalEditPart editPartToRefresh) {
+ super(editPartToRefresh);
+ }
+
+ @Override
+ public void execute() {
+ refresh();
+ }
+
+ @Override
+ public void redo() {
+ refresh();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForUndo.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForUndo.java
index 187fd9778b2..ea260c60d73 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForUndo.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/RefreshCommandForUndo.java
@@ -1,31 +1,31 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.gef.GraphicalEditPart;
-
-/**
- * Refresh the {@link IFigure} of a given {@link GraphicalEditPart} on undo of this command. <br/>
- * <strong>This command must be created before the other ones in a CompoundCommand</strong> since the commands are
- * executed in reverse when undoing.
- * @since 3.0
- */
-public class RefreshCommandForUndo extends AbstractRefreshCommand {
-
- public RefreshCommandForUndo(final GraphicalEditPart editPartToRefresh) {
- super(editPartToRefresh);
- }
-
- @Override
- public void undo() {
- refresh();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.gef.GraphicalEditPart;
+
+/**
+ * Refresh the {@link IFigure} of a given {@link GraphicalEditPart} on undo of this command. <br/>
+ * <strong>This command must be created before the other ones in a CompoundCommand</strong> since the commands are
+ * executed in reverse when undoing.
+ * @since 3.0
+ */
+public class RefreshCommandForUndo extends AbstractRefreshCommand {
+
+ public RefreshCommandForUndo(final GraphicalEditPart editPartToRefresh) {
+ super(editPartToRefresh);
+ }
+
+ @Override
+ public void undo() {
+ refresh();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SelectAndExecuteCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SelectAndExecuteCommand.java
index 21437c1e603..6f0ee879a4f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SelectAndExecuteCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SelectAndExecuteCommand.java
@@ -1,194 +1,194 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.diagram.ui.commands.CommandUtilities;
-import org.eclipse.gmf.runtime.diagram.ui.commands.PopupMenuCommand;
-import org.eclipse.gmf.runtime.diagram.ui.menus.PopupMenu;
-import org.eclipse.gmf.runtime.diagram.ui.menus.PopupMenu.CascadingMenu;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.swt.widgets.Shell;
-
-/**
- * This class opens a dialog to select and execute a command in a given list.
- */
-public class SelectAndExecuteCommand extends PopupMenuCommand {
-
- /** Selected command kept here for undo / re-do purpose */
- private Command _selectedCmd;
-
- /** An object to handle the selection of a default command. May be null. */
- private DefaultActionHandler defaultHandler;
-
- /**
- * The default label provider for the the menu items (Commands) used in this command.
- */
- static public class CommandLabelProvider extends org.eclipse.jface.viewers.LabelProvider {
-
- /**
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- */
- @Override
- public String getText(Object object) {
- String text = super.getText(object);
- if (object instanceof Command) {
- String commandLabel = ((Command) object).getLabel();
- if (commandLabel != null) {
- text = commandLabel;
- }
- }
- return text;
- }
- }
-
- /**
- *
- * Constructor.
- *
- * @param label
- * the command label
- * @param parentShell
- * the parent shell
- * @param content
- * the list of available commands proposed for user selection
- * (List<org.eclipse.gef.commands.Command> expected here)
- */
- public SelectAndExecuteCommand(String label, Shell parentShell, List<Command> content) {
- this(label, parentShell, content, null);
- }
-
- /**
- *
- * Constructor.
- *
- * @param label
- * the command label
- * @param parentShell
- * the parent shell
- * @param content
- * the list of available commands proposed for user selection
- * (List<org.eclipse.gef.commands.Command> expected here)
- * @param handler
- * an object to handle the "default action" case
- */
- public SelectAndExecuteCommand(String label, Shell parentShell, List<Command> content, DefaultActionHandler handler) {
- super(label, parentShell);
-
- this.defaultHandler = handler;
- createPopupMenu(content);
- }
-
- /**
- * Adds a submenu to the popup menu, to handle the "Select default" case
- *
- * @param menu
- */
- protected void createPopupMenu(List<Command> content) {
- PopupMenu popupMenu;
-
- if (defaultHandler != null) {
- // Contains a list of commands + a Default item
- List<Object> menuContents = new LinkedList<Object>(content);
-
- PopupMenu submenu = new PopupMenu(convertToDefault(content), new CommandLabelProvider());
-
- CascadingMenu cascadingMenu = new CascadingMenu(defaultHandler.getLabel(), submenu);
- menuContents.add(cascadingMenu);
-
- popupMenu = new PopupMenu(menuContents, new CommandLabelProvider());
- } else {
- popupMenu = new PopupMenu(content, new CommandLabelProvider());
- }
-
- setPopupMenu(popupMenu);
- }
-
- /**
- * Adds a "Set as default" behavior to a list of commands
- *
- * @param commands
- * @return
- */
- protected List<Command> convertToDefault(List<Command> commands) {
- List<Command> result = new ArrayList<Command>(commands.size());
- for (Command command : commands) {
- final Command commandToExecute = command;
- CompoundCommand compound = new CompoundCommand(commandToExecute.getLabel());
- compound.add(commandToExecute);
- compound.add(new Command("Set default drop behavior") {
-
- @Override
- public void execute() {
- defaultHandler.defaultActionSelected(commandToExecute);
- }
-
- });
-
- result.add(compound);
- }
- return result;
- }
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, org.eclipse.core.runtime.IAdaptable info) throws ExecutionException {
- CommandResult cmdResult = super.doExecuteWithResult(progressMonitor, info);
- if (!cmdResult.getStatus().isOK()) {
- if (cmdResult.getStatus().getSeverity() != IStatus.CANCEL) {
- Activator.log.error(cmdResult.getStatus().getException());
- }
- return cmdResult;
- }
-
- Object returnValue = cmdResult.getReturnValue();
- if (returnValue instanceof List<?>) {
- _selectedCmd = (Command) ((List<?>) returnValue).get(((List<?>) returnValue).size() - 1); // Returns the last command
- } else {
- _selectedCmd = (Command) cmdResult.getReturnValue();
- }
- Assert.isTrue(_selectedCmd != null && _selectedCmd.canExecute());
- _selectedCmd.execute();
-
- return CommandResult.newOKCommandResult();
- }
-
- @Override
- protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- if (_selectedCmd != null && _selectedCmd.canUndo()) {
- _selectedCmd.undo();
- }
- return super.doUndoWithResult(progressMonitor, info);
- }
-
- @Override
- protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
-
- if (_selectedCmd != null && CommandUtilities.canRedo(_selectedCmd)) {
- _selectedCmd.redo();
- }
- return super.doRedoWithResult(progressMonitor, info);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.diagram.ui.commands.CommandUtilities;
+import org.eclipse.gmf.runtime.diagram.ui.commands.PopupMenuCommand;
+import org.eclipse.gmf.runtime.diagram.ui.menus.PopupMenu;
+import org.eclipse.gmf.runtime.diagram.ui.menus.PopupMenu.CascadingMenu;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * This class opens a dialog to select and execute a command in a given list.
+ */
+public class SelectAndExecuteCommand extends PopupMenuCommand {
+
+ /** Selected command kept here for undo / re-do purpose */
+ private Command _selectedCmd;
+
+ /** An object to handle the selection of a default command. May be null. */
+ private DefaultActionHandler defaultHandler;
+
+ /**
+ * The default label provider for the the menu items (Commands) used in this command.
+ */
+ static public class CommandLabelProvider extends org.eclipse.jface.viewers.LabelProvider {
+
+ /**
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ */
+ @Override
+ public String getText(Object object) {
+ String text = super.getText(object);
+ if (object instanceof Command) {
+ String commandLabel = ((Command) object).getLabel();
+ if (commandLabel != null) {
+ text = commandLabel;
+ }
+ }
+ return text;
+ }
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param label
+ * the command label
+ * @param parentShell
+ * the parent shell
+ * @param content
+ * the list of available commands proposed for user selection
+ * (List<org.eclipse.gef.commands.Command> expected here)
+ */
+ public SelectAndExecuteCommand(String label, Shell parentShell, List<Command> content) {
+ this(label, parentShell, content, null);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param label
+ * the command label
+ * @param parentShell
+ * the parent shell
+ * @param content
+ * the list of available commands proposed for user selection
+ * (List<org.eclipse.gef.commands.Command> expected here)
+ * @param handler
+ * an object to handle the "default action" case
+ */
+ public SelectAndExecuteCommand(String label, Shell parentShell, List<Command> content, DefaultActionHandler handler) {
+ super(label, parentShell);
+
+ this.defaultHandler = handler;
+ createPopupMenu(content);
+ }
+
+ /**
+ * Adds a submenu to the popup menu, to handle the "Select default" case
+ *
+ * @param menu
+ */
+ protected void createPopupMenu(List<Command> content) {
+ PopupMenu popupMenu;
+
+ if (defaultHandler != null) {
+ // Contains a list of commands + a Default item
+ List<Object> menuContents = new LinkedList<Object>(content);
+
+ PopupMenu submenu = new PopupMenu(convertToDefault(content), new CommandLabelProvider());
+
+ CascadingMenu cascadingMenu = new CascadingMenu(defaultHandler.getLabel(), submenu);
+ menuContents.add(cascadingMenu);
+
+ popupMenu = new PopupMenu(menuContents, new CommandLabelProvider());
+ } else {
+ popupMenu = new PopupMenu(content, new CommandLabelProvider());
+ }
+
+ setPopupMenu(popupMenu);
+ }
+
+ /**
+ * Adds a "Set as default" behavior to a list of commands
+ *
+ * @param commands
+ * @return
+ */
+ protected List<Command> convertToDefault(List<Command> commands) {
+ List<Command> result = new ArrayList<Command>(commands.size());
+ for (Command command : commands) {
+ final Command commandToExecute = command;
+ CompoundCommand compound = new CompoundCommand(commandToExecute.getLabel());
+ compound.add(commandToExecute);
+ compound.add(new Command("Set default drop behavior") {
+
+ @Override
+ public void execute() {
+ defaultHandler.defaultActionSelected(commandToExecute);
+ }
+
+ });
+
+ result.add(compound);
+ }
+ return result;
+ }
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, org.eclipse.core.runtime.IAdaptable info) throws ExecutionException {
+ CommandResult cmdResult = super.doExecuteWithResult(progressMonitor, info);
+ if (!cmdResult.getStatus().isOK()) {
+ if (cmdResult.getStatus().getSeverity() != IStatus.CANCEL) {
+ Activator.log.error(cmdResult.getStatus().getException());
+ }
+ return cmdResult;
+ }
+
+ Object returnValue = cmdResult.getReturnValue();
+ if (returnValue instanceof List<?>) {
+ _selectedCmd = (Command) ((List<?>) returnValue).get(((List<?>) returnValue).size() - 1); // Returns the last command
+ } else {
+ _selectedCmd = (Command) cmdResult.getReturnValue();
+ }
+ Assert.isTrue(_selectedCmd != null && _selectedCmd.canExecute());
+ _selectedCmd.execute();
+
+ return CommandResult.newOKCommandResult();
+ }
+
+ @Override
+ protected CommandResult doUndoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+ if (_selectedCmd != null && _selectedCmd.canUndo()) {
+ _selectedCmd.undo();
+ }
+ return super.doUndoWithResult(progressMonitor, info);
+ }
+
+ @Override
+ protected CommandResult doRedoWithResult(IProgressMonitor progressMonitor, IAdaptable info) throws ExecutionException {
+
+ if (_selectedCmd != null && CommandUtilities.canRedo(_selectedCmd)) {
+ _selectedCmd.redo();
+ }
+ return super.doRedoWithResult(progressMonitor, info);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticAdapter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticAdapter.java
index b72aaa0aca5..5499a902ef7 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticAdapter.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticAdapter.java
@@ -1,99 +1,99 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
-import org.eclipse.gmf.runtime.emf.core.util.IProxyEObject;
-import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * The Class SemanticAdapter used to package semantic or view element in a
- * deferred command
- */
-public class SemanticAdapter implements IAdaptable, IProxyEObject {
-
- /** The element. */
- private Object element;
-
- /** The view. */
- private Object view;
-
- /**
- * Instantiates a new semantic adapter.
- *
- * @param element
- * the element
- * @param view
- * the view
- */
- public SemanticAdapter(EObject element, Object view) {
- this.element = element;
- this.view = view;
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter.equals(EObject.class)) {
- return element;
- }
- if (adapter.equals(View.class)) {
- return view;
- }
- return null;
- }
-
- /**
- * Sets the element.
- *
- * @param element
- * the new element
- */
- // @unused
- public void setElement(Object element) {
- this.element = element;
- }
-
- /**
- * Sets the view.
- *
- * @param view
- * the new view
- */
- public void setView(Object view) {
- this.view = view;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object getProxyClassID() {
- return (element != null) ? PackageUtil.getID(EMFCoreUtil.getProxyClass((EObject) element)) : null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public EObject resolve() {
- return (element != null) ? (EObject) element : null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.emf.core.util.IProxyEObject;
+import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * The Class SemanticAdapter used to package semantic or view element in a
+ * deferred command
+ */
+public class SemanticAdapter implements IAdaptable, IProxyEObject {
+
+ /** The element. */
+ private Object element;
+
+ /** The view. */
+ private Object view;
+
+ /**
+ * Instantiates a new semantic adapter.
+ *
+ * @param element
+ * the element
+ * @param view
+ * the view
+ */
+ public SemanticAdapter(EObject element, Object view) {
+ this.element = element;
+ this.view = view;
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter.equals(EObject.class)) {
+ return element;
+ }
+ if (adapter.equals(View.class)) {
+ return view;
+ }
+ return null;
+ }
+
+ /**
+ * Sets the element.
+ *
+ * @param element
+ * the new element
+ */
+ // @unused
+ public void setElement(Object element) {
+ this.element = element;
+ }
+
+ /**
+ * Sets the view.
+ *
+ * @param view
+ * the new view
+ */
+ public void setView(Object view) {
+ this.view = view;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getProxyClassID() {
+ return (element != null) ? PackageUtil.getID(EMFCoreUtil.getProxyClass((EObject) element)) : null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public EObject resolve() {
+ return (element != null) ? (EObject) element : null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticElementAdapter.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticElementAdapter.java
index 56bd7ce7b30..f52ec16977a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticElementAdapter.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SemanticElementAdapter.java
@@ -1,88 +1,88 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * An adapter for {@link IElementType}, {@link EObject} or {@link View}.
- */
-public class SemanticElementAdapter extends SemanticAdapter implements ISemanticHintAdapter {
-
- /** The elementType. */
- private Object elementType;
-
- /** Constructor from EObject */
- public SemanticElementAdapter(EObject element) {
- super(element, null);
- this.elementType = null;
- }
-
- /** Constructor from IElementType */
- public SemanticElementAdapter(IElementType elementType) {
- super(null, null);
- this.elementType = elementType;
- }
-
- /** Constructor from EObject and IElementType */
- public SemanticElementAdapter(EObject element, IElementType elementType) {
- super(element, null);
- this.elementType = elementType;
- }
-
- /**
- * {@inheritDoc}
- */
- @SuppressWarnings("rawtypes")
- @Override
- public Object getAdapter(Class adapter) {
- if (adapter.equals(IHintedType.class)) {
- if (elementType instanceof IHintedType) {
- return elementType;
- }
- }
-
- if (adapter.equals(IElementType.class)) {
- return elementType;
- }
- return super.getAdapter(adapter);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object getProxyClassID() {
- if (elementType != null) {
- return PackageUtil.getID(((IElementType) elementType).getEClass());
- }
- return super.getProxyClassID();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getSemanticHint() {
- if (elementType instanceof IHintedType) {
- return ((IHintedType) elementType).getSemanticHint();
- }
- return null;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.emf.core.util.PackageUtil;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.emf.type.core.IHintedType;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * An adapter for {@link IElementType}, {@link EObject} or {@link View}.
+ */
+public class SemanticElementAdapter extends SemanticAdapter implements ISemanticHintAdapter {
+
+ /** The elementType. */
+ private Object elementType;
+
+ /** Constructor from EObject */
+ public SemanticElementAdapter(EObject element) {
+ super(element, null);
+ this.elementType = null;
+ }
+
+ /** Constructor from IElementType */
+ public SemanticElementAdapter(IElementType elementType) {
+ super(null, null);
+ this.elementType = elementType;
+ }
+
+ /** Constructor from EObject and IElementType */
+ public SemanticElementAdapter(EObject element, IElementType elementType) {
+ super(element, null);
+ this.elementType = elementType;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @SuppressWarnings("rawtypes")
+ @Override
+ public Object getAdapter(Class adapter) {
+ if (adapter.equals(IHintedType.class)) {
+ if (elementType instanceof IHintedType) {
+ return elementType;
+ }
+ }
+
+ if (adapter.equals(IElementType.class)) {
+ return elementType;
+ }
+ return super.getAdapter(adapter);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getProxyClassID() {
+ if (elementType != null) {
+ return PackageUtil.getID(((IElementType) elementType).getEClass());
+ }
+ return super.getProxyClassID();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getSemanticHint() {
+ if (elementType instanceof IHintedType) {
+ return ((IHintedType) elementType).getSemanticHint();
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SetNodeVisibilityCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SetNodeVisibilityCommand.java
index f55666f6ecd..484faac3c36 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SetNodeVisibilityCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/SetNodeVisibilityCommand.java
@@ -1,47 +1,47 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands;
-
-import org.eclipse.emf.transaction.RecordingCommand;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class SetNodeVisibilityCommand extends RecordingCommand {
-
- /** view to modify */
- protected View view;
-
- /** visibility to set */
- protected Boolean isVisible;
-
- public SetNodeVisibilityCommand(TransactionalEditingDomain domain, View view, Boolean isVisible) {
- super(domain, "Set Node Visibility");
- this.view = view;
- this.isVisible = isVisible;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void doExecute() {
- if (null != view) {
- if (view.isVisible() != isVisible) {
- view.setVisible(isVisible);
- }
- }
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands;
+
+import org.eclipse.emf.transaction.RecordingCommand;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+public class SetNodeVisibilityCommand extends RecordingCommand {
+
+ /** view to modify */
+ protected View view;
+
+ /** visibility to set */
+ protected Boolean isVisible;
+
+ public SetNodeVisibilityCommand(TransactionalEditingDomain domain, View view, Boolean isVisible) {
+ super(domain, "Set Node Visibility");
+ this.view = view;
+ this.isVisible = isVisible;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void doExecute() {
+ if (null != view) {
+ if (view.isVisible() != isVisible) {
+ view.setVisible(isVisible);
+ }
+ }
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/requests/ShowHideRelatedLinkRequest.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/requests/ShowHideRelatedLinkRequest.java
index df47d22d8c0..1ef1aef3542 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/requests/ShowHideRelatedLinkRequest.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/commands/requests/ShowHideRelatedLinkRequest.java
@@ -1,78 +1,78 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.commands.requests;
-
-import java.util.Collection;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-
-/**
- *
- * The request used to show/hide related links
- *
- */
-public class ShowHideRelatedLinkRequest extends Request {
-
- /**
- *
- * this enumeration describe the several ways to use this request
- *
- */
- public static enum ShowHideKind {
- OPEN_DIALOG, SHOW_ALL_LINK_IN_DIAGRAM, SHOW_ALL_LINK_BETWEEN_SELECTED_ELEMENT
- };
-
- /**
- * the list of the selected editpart
- */
- private final Collection<EditPart> selectedEditParts;
-
-
- /**
- * the way to use this request
- */
- private final ShowHideKind mode;
-
- /**
- *
- * Constructor.
- *
- * @param selectedEditPart
- */
- public ShowHideRelatedLinkRequest(final Collection<EditPart> selectedEditPart, final ShowHideKind mode) {
- super();
- this.selectedEditParts = selectedEditPart;
- this.mode = mode;
- }
-
- /**
- *
- * @return
- * the selected edit part
- */
- public Collection<EditPart> getSelectedEditParts() {
- return selectedEditParts;
- }
-
- /**
- *
- * @return
- * the mode to use this request
- */
- public ShowHideKind getMode() {
- return mode;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.commands.requests;
+
+import java.util.Collection;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+
+/**
+ *
+ * The request used to show/hide related links
+ *
+ */
+public class ShowHideRelatedLinkRequest extends Request {
+
+ /**
+ *
+ * this enumeration describe the several ways to use this request
+ *
+ */
+ public static enum ShowHideKind {
+ OPEN_DIALOG, SHOW_ALL_LINK_IN_DIAGRAM, SHOW_ALL_LINK_BETWEEN_SELECTED_ELEMENT
+ };
+
+ /**
+ * the list of the selected editpart
+ */
+ private final Collection<EditPart> selectedEditParts;
+
+
+ /**
+ * the way to use this request
+ */
+ private final ShowHideKind mode;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param selectedEditPart
+ */
+ public ShowHideRelatedLinkRequest(final Collection<EditPart> selectedEditPart, final ShowHideKind mode) {
+ super();
+ this.selectedEditParts = selectedEditPart;
+ this.mode = mode;
+ }
+
+ /**
+ *
+ * @return
+ * the selected edit part
+ */
+ public Collection<EditPart> getSelectedEditParts() {
+ return selectedEditParts;
+ }
+
+ /**
+ *
+ * @return
+ * the mode to use this request
+ */
+ public ShowHideKind getMode() {
+ return mode;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AbstractCustomStyleListValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AbstractCustomStyleListValueCommand.java
index 9b6d4724814..10b3216b133 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AbstractCustomStyleListValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AbstractCustomStyleListValueCommand.java
@@ -1,100 +1,100 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.AbstractCommand;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NamedStyle;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public abstract class AbstractCustomStyleListValueCommand extends AbstractCommand {
-
- protected View view;
-
- protected EClass styleClass;
-
- protected String styleName;
-
- protected boolean needsCreate;
-
- protected EStructuralFeature styleFeature;
-
- protected EditingDomain domain;
-
- protected Command command;
-
- protected NamedStyle style;
-
- public AbstractCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature) {
- this.view = view;
- this.styleName = styleName;
- this.styleClass = styleClass;
- this.styleFeature = styleFeature;
- this.domain = domain;
- }
-
- @Override
- public void execute() {
- // FIXME: Related to CompoundCommand vs StrictCompoundCommand.
- // Sometimes, canExecute() is not called, and the command is not prepared
- if (!isPrepared) {
- prepare();
- isPrepared = true;
- }
-
- if (needsCreate) {
- view.getStyles().add(style);
- }
- command.execute();
- }
-
- @Override
- public void redo() {
- execute();
- }
-
- @Override
- public boolean prepare() {
- style = view.getNamedStyle(styleClass, styleName);
-
- // The style may be volatile (generated by CSS). If it doesn't belong to the view, it will need to be attached.
- if (needsCreate = (style == null)) {
- style = (NamedStyle) NotationFactory.eINSTANCE.create(styleClass);
- style.setName(styleName);
- } else if (style.eResource() == null) {
- needsCreate = true;
- }
-
- command = createCommand();
-
- // return true;
- return command.canExecute();
- }
-
- protected abstract Command createCommand();
-
- @Override
- public void undo() {
- EList currentList = (EList) (style.eGet(styleFeature));
- command.undo();
- if (needsCreate) {
- view.getStyles().remove(style);
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.AbstractCommand;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public abstract class AbstractCustomStyleListValueCommand extends AbstractCommand {
+
+ protected View view;
+
+ protected EClass styleClass;
+
+ protected String styleName;
+
+ protected boolean needsCreate;
+
+ protected EStructuralFeature styleFeature;
+
+ protected EditingDomain domain;
+
+ protected Command command;
+
+ protected NamedStyle style;
+
+ public AbstractCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature) {
+ this.view = view;
+ this.styleName = styleName;
+ this.styleClass = styleClass;
+ this.styleFeature = styleFeature;
+ this.domain = domain;
+ }
+
+ @Override
+ public void execute() {
+ // FIXME: Related to CompoundCommand vs StrictCompoundCommand.
+ // Sometimes, canExecute() is not called, and the command is not prepared
+ if (!isPrepared) {
+ prepare();
+ isPrepared = true;
+ }
+
+ if (needsCreate) {
+ view.getStyles().add(style);
+ }
+ command.execute();
+ }
+
+ @Override
+ public void redo() {
+ execute();
+ }
+
+ @Override
+ public boolean prepare() {
+ style = view.getNamedStyle(styleClass, styleName);
+
+ // The style may be volatile (generated by CSS). If it doesn't belong to the view, it will need to be attached.
+ if (needsCreate = (style == null)) {
+ style = (NamedStyle) NotationFactory.eINSTANCE.create(styleClass);
+ style.setName(styleName);
+ } else if (style.eResource() == null) {
+ needsCreate = true;
+ }
+
+ command = createCommand();
+
+ // return true;
+ return command.canExecute();
+ }
+
+ protected abstract Command createCommand();
+
+ @Override
+ public void undo() {
+ EList currentList = (EList) (style.eGet(styleFeature));
+ command.undo();
+ if (needsCreate) {
+ view.getStyles().remove(style);
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddAllCustomStyleListValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddAllCustomStyleListValueCommand.java
index f87913b3fc2..14959e96f2d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddAllCustomStyleListValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddAllCustomStyleListValueCommand.java
@@ -1,45 +1,45 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import java.util.Collection;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.edit.command.CommandParameter;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class AddAllCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
-
- protected int index = CommandParameter.NO_INDEX;
-
- protected Collection<?> values;
-
- public AddAllCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature, Collection<?> values, int index) {
- super(domain, view, styleName, styleClass, styleFeature);
- this.index = index;
- this.values = values;
- }
-
- public AddAllCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature feature, Collection<?> values) {
- this(domain, view, styleName, styleClass, feature, values, CommandParameter.NO_INDEX);
- }
-
- @Override
- protected Command createCommand() {
- return AddCommand.create(domain, style, styleFeature, values, index);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class AddAllCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
+
+ protected int index = CommandParameter.NO_INDEX;
+
+ protected Collection<?> values;
+
+ public AddAllCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature, Collection<?> values, int index) {
+ super(domain, view, styleName, styleClass, styleFeature);
+ this.index = index;
+ this.values = values;
+ }
+
+ public AddAllCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature feature, Collection<?> values) {
+ this(domain, view, styleName, styleClass, feature, values, CommandParameter.NO_INDEX);
+ }
+
+ @Override
+ protected Command createCommand() {
+ return AddCommand.create(domain, style, styleFeature, values, index);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddCustomStyleListValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddCustomStyleListValueCommand.java
index bda9ff6e4f9..51a6a5ec258 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddCustomStyleListValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/AddCustomStyleListValueCommand.java
@@ -1,44 +1,44 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.AddCommand;
-import org.eclipse.emf.edit.command.CommandParameter;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class AddCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
-
- protected int index = CommandParameter.NO_INDEX;
-
- protected Object value;
-
- public AddCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature, Object value, int index) {
- super(domain, view, styleName, styleClass, styleFeature);
- this.index = index;
- this.value = value;
- }
-
- public AddCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature, Object value) {
- this(domain, view, styleName, styleClass, styleFeature, value, CommandParameter.NO_INDEX);
- }
-
- @Override
- protected Command createCommand() {
- return AddCommand.create(domain, style, styleFeature, value, index);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.AddCommand;
+import org.eclipse.emf.edit.command.CommandParameter;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class AddCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
+
+ protected int index = CommandParameter.NO_INDEX;
+
+ protected Object value;
+
+ public AddCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature, Object value, int index) {
+ super(domain, view, styleName, styleClass, styleFeature);
+ this.index = index;
+ this.value = value;
+ }
+
+ public AddCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass styleClass, EStructuralFeature styleFeature, Object value) {
+ this(domain, view, styleName, styleClass, styleFeature, value, CommandParameter.NO_INDEX);
+ }
+
+ @Override
+ protected Command createCommand() {
+ return AddCommand.create(domain, style, styleFeature, value, index);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableList.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableList.java
index e81406982cf..d95cb32f164 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableList.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableList.java
@@ -1,24 +1,24 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class CustomBooleanStyleObservableList extends CustomStyleObservableList {
-
- public CustomBooleanStyleObservableList(View view, EditingDomain domain, String styleName) {
- super(view, styleName, domain, NotationPackage.eINSTANCE.getBooleanListValueStyle(), NotationPackage.eINSTANCE.getBooleanListValueStyle_BooleanListValue());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+public class CustomBooleanStyleObservableList extends CustomStyleObservableList {
+
+ public CustomBooleanStyleObservableList(View view, EditingDomain domain, String styleName) {
+ super(view, styleName, domain, NotationPackage.eINSTANCE.getBooleanListValueStyle(), NotationPackage.eINSTANCE.getBooleanListValueStyle_BooleanListValue());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableValue.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableValue.java
index 292ee8d651a..ba46073d840 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableValue.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomBooleanStyleObservableValue.java
@@ -1,49 +1,49 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class CustomBooleanStyleObservableValue extends AbstractCustomStyleObservableValue {
-
- public CustomBooleanStyleObservableValue(View source, EditingDomain domain, String styleName) {
- super(source, domain, styleName, NotationPackage.eINSTANCE.getBooleanValueStyle(), NotationPackage.eINSTANCE.getBooleanValueStyle_BooleanValue());
- }
-
- @Override
- public Object getValueType() {
- return Boolean.class;
- }
-
- /**
- * Gets the default value when this style is not set.
- * Subclasses may override
- *
- * @return The default value for this BooleanStyleValue
- */
- @Override
- protected Boolean getDefaultValue() {
- return false;
- }
-
- @Override
- public Command getCommand(Object value) {
- if (value instanceof Boolean) {
- return super.getCommand(value);
- }
- throw new IllegalArgumentException("The value " + value + " is not a valid Boolean Value");
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class CustomBooleanStyleObservableValue extends AbstractCustomStyleObservableValue {
+
+ public CustomBooleanStyleObservableValue(View source, EditingDomain domain, String styleName) {
+ super(source, domain, styleName, NotationPackage.eINSTANCE.getBooleanValueStyle(), NotationPackage.eINSTANCE.getBooleanValueStyle_BooleanValue());
+ }
+
+ @Override
+ public Object getValueType() {
+ return Boolean.class;
+ }
+
+ /**
+ * Gets the default value when this style is not set.
+ * Subclasses may override
+ *
+ * @return The default value for this BooleanStyleValue
+ */
+ @Override
+ protected Boolean getDefaultValue() {
+ return false;
+ }
+
+ @Override
+ public Command getCommand(Object value) {
+ if (value instanceof Boolean) {
+ return super.getCommand(value);
+ }
+ throw new IllegalArgumentException("The value " + value + " is not a valid Boolean Value");
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableList.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableList.java
index 54ce15b14cb..4da62d1ed88 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableList.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableList.java
@@ -1,25 +1,25 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class CustomEObjectStyleObservableList extends CustomStyleObservableList {
-
- // TODO: The super class is probably powerful enough to handle EObjects.
- public CustomEObjectStyleObservableList(View view, EditingDomain domain, String styleName) {
- super(view, styleName, domain, NotationPackage.eINSTANCE.getEObjectListValueStyle(), NotationPackage.eINSTANCE.getEObjectListValueStyle_EObjectListValue());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+public class CustomEObjectStyleObservableList extends CustomStyleObservableList {
+
+ // TODO: The super class is probably powerful enough to handle EObjects.
+ public CustomEObjectStyleObservableList(View view, EditingDomain domain, String styleName) {
+ super(view, styleName, domain, NotationPackage.eINSTANCE.getEObjectListValueStyle(), NotationPackage.eINSTANCE.getEObjectListValueStyle_EObjectListValue());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableValue.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableValue.java
index 279c539162c..29559151db4 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableValue.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomEObjectStyleObservableValue.java
@@ -1,50 +1,50 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class CustomEObjectStyleObservableValue extends AbstractCustomStyleObservableValue {
-
- public CustomEObjectStyleObservableValue(View source, EditingDomain domain, String styleName) {
- super(source, domain, styleName, NotationPackage.eINSTANCE.getEObjectValueStyle(), NotationPackage.eINSTANCE.getEObjectValueStyle_EObjectValue());
- }
-
- @Override
- public Object getValueType() {
- return EObject.class;
- }
-
- /**
- * Gets the default value when this style is not set.
- * Subclasses may override
- *
- * @return The default value for this EObjectStyleValue
- */
- @Override
- protected EObject getDefaultValue() {
- return null;
- }
-
- @Override
- public Command getCommand(Object value) {
- if (value instanceof EObject) {
- return super.getCommand(value);
- }
- throw new IllegalArgumentException("The value " + value + " is not a valid EObject Value");
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class CustomEObjectStyleObservableValue extends AbstractCustomStyleObservableValue {
+
+ public CustomEObjectStyleObservableValue(View source, EditingDomain domain, String styleName) {
+ super(source, domain, styleName, NotationPackage.eINSTANCE.getEObjectValueStyle(), NotationPackage.eINSTANCE.getEObjectValueStyle_EObjectValue());
+ }
+
+ @Override
+ public Object getValueType() {
+ return EObject.class;
+ }
+
+ /**
+ * Gets the default value when this style is not set.
+ * Subclasses may override
+ *
+ * @return The default value for this EObjectStyleValue
+ */
+ @Override
+ protected EObject getDefaultValue() {
+ return null;
+ }
+
+ @Override
+ public Command getCommand(Object value) {
+ if (value instanceof EObject) {
+ return super.getCommand(value);
+ }
+ throw new IllegalArgumentException("The value " + value + " is not a valid EObject Value");
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableList.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableList.java
index 4718866e3c2..909c200de1e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableList.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableList.java
@@ -1,24 +1,24 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class CustomIntStyleObservableList extends CustomStyleObservableList {
-
- public CustomIntStyleObservableList(View view, EditingDomain domain, String styleName) {
- super(view, styleName, domain, NotationPackage.eINSTANCE.getIntListValueStyle(), NotationPackage.eINSTANCE.getIntListValueStyle_IntListValue());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+public class CustomIntStyleObservableList extends CustomStyleObservableList {
+
+ public CustomIntStyleObservableList(View view, EditingDomain domain, String styleName) {
+ super(view, styleName, domain, NotationPackage.eINSTANCE.getIntListValueStyle(), NotationPackage.eINSTANCE.getIntListValueStyle_IntListValue());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableValue.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableValue.java
index 2f1329f9028..22327d26b4c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableValue.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomIntStyleObservableValue.java
@@ -1,49 +1,49 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class CustomIntStyleObservableValue extends AbstractCustomStyleObservableValue {
-
- public CustomIntStyleObservableValue(View source, EditingDomain domain, String styleName) {
- super(source, domain, styleName, NotationPackage.eINSTANCE.getIntValueStyle(), NotationPackage.eINSTANCE.getIntValueStyle_IntValue());
- }
-
- @Override
- public Object getValueType() {
- return Integer.class;
- }
-
- /**
- * Gets the default value when this style is not set.
- * Subclasses may override
- *
- * @return The default value for this IntegerStyleValue
- */
- @Override
- protected Integer getDefaultValue() {
- return 0;
- }
-
- @Override
- public Command getCommand(Object value) {
- if (value instanceof Integer) {
- return super.getCommand(value);
- }
- throw new IllegalArgumentException("The value " + value + " is not a valid Integer Value");
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class CustomIntStyleObservableValue extends AbstractCustomStyleObservableValue {
+
+ public CustomIntStyleObservableValue(View source, EditingDomain domain, String styleName) {
+ super(source, domain, styleName, NotationPackage.eINSTANCE.getIntValueStyle(), NotationPackage.eINSTANCE.getIntValueStyle_IntValue());
+ }
+
+ @Override
+ public Object getValueType() {
+ return Integer.class;
+ }
+
+ /**
+ * Gets the default value when this style is not set.
+ * Subclasses may override
+ *
+ * @return The default value for this IntegerStyleValue
+ */
+ @Override
+ protected Integer getDefaultValue() {
+ return 0;
+ }
+
+ @Override
+ public Command getCommand(Object value) {
+ if (value instanceof Integer) {
+ return super.getCommand(value);
+ }
+ throw new IllegalArgumentException("The value " + value + " is not a valid Integer Value");
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableList.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableList.java
index 6de76651d13..e97a9d0ef83 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableList.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableList.java
@@ -1,24 +1,24 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-public class CustomStringStyleObservableList extends CustomStyleObservableList {
-
- public CustomStringStyleObservableList(View view, EditingDomain domain, String styleName) {
- super(view, styleName, domain, NotationPackage.eINSTANCE.getStringListValueStyle(), NotationPackage.eINSTANCE.getStringListValueStyle_StringListValue());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+public class CustomStringStyleObservableList extends CustomStyleObservableList {
+
+ public CustomStringStyleObservableList(View view, EditingDomain domain, String styleName) {
+ super(view, styleName, domain, NotationPackage.eINSTANCE.getStringListValueStyle(), NotationPackage.eINSTANCE.getStringListValueStyle_StringListValue());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableValue.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableValue.java
index b8f39fa8a84..46c4f0141d2 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableValue.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStringStyleObservableValue.java
@@ -1,49 +1,49 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class CustomStringStyleObservableValue extends AbstractCustomStyleObservableValue {
-
- public CustomStringStyleObservableValue(View source, EditingDomain domain, String styleName) {
- super(source, domain, styleName, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue());
- }
-
- @Override
- public Object getValueType() {
- return String.class;
- }
-
- /**
- * Gets the default value when this style is not set.
- * Subclasses may override
- *
- * @return The default value for this StringStyleValue
- */
- @Override
- protected String getDefaultValue() {
- return ""; //$NON-NLS-1$
- }
-
- @Override
- public Command getCommand(Object value) {
- if (value instanceof String) {
- return super.getCommand(value);
- }
- throw new IllegalArgumentException("The value " + value + " is not a valid String Value");
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class CustomStringStyleObservableValue extends AbstractCustomStyleObservableValue {
+
+ public CustomStringStyleObservableValue(View source, EditingDomain domain, String styleName) {
+ super(source, domain, styleName, NotationPackage.eINSTANCE.getStringValueStyle(), NotationPackage.eINSTANCE.getStringValueStyle_StringValue());
+ }
+
+ @Override
+ public Object getValueType() {
+ return String.class;
+ }
+
+ /**
+ * Gets the default value when this style is not set.
+ * Subclasses may override
+ *
+ * @return The default value for this StringStyleValue
+ */
+ @Override
+ protected String getDefaultValue() {
+ return ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public Command getCommand(Object value) {
+ if (value instanceof String) {
+ return super.getCommand(value);
+ }
+ throw new IllegalArgumentException("The value " + value + " is not a valid String Value");
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleObservableList.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleObservableList.java
index 57af8853b45..da8f7dedc0a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleObservableList.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/CustomStyleObservableList.java
@@ -1,179 +1,179 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.core.databinding.observable.ChangeEvent;
-import org.eclipse.core.databinding.observable.IChangeListener;
-import org.eclipse.core.databinding.observable.list.IObservableList;
-import org.eclipse.core.databinding.observable.list.WritableList;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.databinding.EMFProperties;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.NamedStyle;
-import org.eclipse.gmf.runtime.notation.Style;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.listener.CustomStyleListener;
-import org.eclipse.papyrus.infra.ui.emf.databinding.EMFObservableList;
-import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
-
-
-public class CustomStyleObservableList extends EMFObservableList implements IChangeListener {
-
- protected EClass eClass;
-
- protected String styleName;
-
- protected View view;
-
- protected EditingDomain domain;
-
- protected CustomStyleListener listener;
-
- protected boolean styleExists;
-
- protected boolean changing = false;
-
- // Equals to concreteList
- protected IObservableList observableConcreteList;
-
- // protected final List<?> transientList;
-
- public CustomStyleObservableList(View view, String styleName, EditingDomain domain, EClass eClass, EStructuralFeature feature) {
- super(getWrappedList(view, styleName, eClass, feature), domain, null, null);
- this.eClass = eClass;
- this.feature = feature;
- this.styleName = styleName;
- this.view = view;
- this.domain = domain;
- observableConcreteList = (IObservableList) concreteList;
- styleExists = styleExists();
-
- view.eAdapters().add(listener = new CustomStyleListener(view, feature, this, styleName));
- }
-
- @Override
- public void commit(AbstractEditor editor) {
- changing = true;
- super.commit(editor);
- changing = false;
- }
-
- protected boolean styleExists() {
- // getNamedStyle may return a volatile result when CSS are available. We want a persistent element, so we should call directly view#getStyles()
- // Call directly view.getStyles() instead of view.getNamedStyle()
- for (Style style : (List<Style>) view.getStyles()) {
- if (eClass.isInstance(style)) {
- NamedStyle namedStyle = (NamedStyle) style;
- if (styleName.equals(namedStyle.getName())) {
- return true;
- }
- }
- }
-
- return false;
- }
-
- protected boolean isStyleCreated() {
- return getNamedStyle() != null;
- }
-
- protected NamedStyle getNamedStyle() {
- return view.getNamedStyle(eClass, styleName);
- }
-
- private static IObservableList getWrappedList(View view, String styleName, EClass eClass, EStructuralFeature feature) {
- NamedStyle style = view.getNamedStyle(eClass, styleName);
-
- if (style != null) {
- return EMFProperties.list(feature).observe(style);
- }
-
- // The style doesn't exist yet, we need to simulate it
- // (With an empty list)
- return new WritableList();
- }
-
- @Override
- public Command getAddCommand(int index, Object value) {
- return new AddCustomStyleListValueCommand(domain, view, styleName, eClass, feature, value, index);
- }
-
- @Override
- public Command getAddCommand(Object value) {
- return new AddCustomStyleListValueCommand(domain, view, styleName, eClass, feature, value);
- }
-
- @Override
- public Command getAddAllCommand(Collection<?> values) {
- return new AddAllCustomStyleListValueCommand(domain, view, styleName, eClass, feature, values);
- }
-
- @Override
- public Command getAddAllCommand(int index, Collection<?> values) {
- return new AddCustomStyleListValueCommand(domain, view, styleName, eClass, feature, values, index);
- }
-
- @Override
- public Command getRemoveCommand(Object value) {
- return new RemoveCustomStyleListValueCommand(domain, view, styleName, eClass, feature, value);
- }
-
- @Override
- public Command getRemoveAllCommand(Collection<?> values) {
- return new RemoveAllCustomStyleListValueCommand(domain, view, styleName, eClass, feature, values);
- }
-
- @Override
- public Command getSetCommand(int index, Object value) {
- return new SetCustomStyleListValueCommand(domain, view, styleName, eClass, feature, index, value);
- }
-
- @Override
- public void handleChange(ChangeEvent event) {
- // If the ListValueStyle has been created or removed, we need to resync
- // the concrete list with it
- if (styleExists != (styleExists = styleExists())) {
- observableConcreteList.dispose();
- concreteList = observableConcreteList = getConcreteList();
- observableConcreteList.addChangeListener(this);
- }
-
- // If this observable is not the source of the change, the wrapped
- // list should also be refreshed.
- if (!changing) {
- refreshCacheList();
- }
- }
-
- protected IObservableList getConcreteList() {
- return getWrappedList(view, styleName, eClass, feature);
- }
-
- @Override
- public void dispose() {
- if (isDisposed()) {
- return;
- }
- if (listener != null) {
- view.eAdapters().remove(listener);
- listener.dispose();
- listener = null;
- }
- observableConcreteList.dispose();
- super.dispose();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.list.IObservableList;
+import org.eclipse.core.databinding.observable.list.WritableList;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.databinding.EMFProperties;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.Style;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.listener.CustomStyleListener;
+import org.eclipse.papyrus.infra.ui.emf.databinding.EMFObservableList;
+import org.eclipse.papyrus.infra.widgets.editors.AbstractEditor;
+
+
+public class CustomStyleObservableList extends EMFObservableList implements IChangeListener {
+
+ protected EClass eClass;
+
+ protected String styleName;
+
+ protected View view;
+
+ protected EditingDomain domain;
+
+ protected CustomStyleListener listener;
+
+ protected boolean styleExists;
+
+ protected boolean changing = false;
+
+ // Equals to concreteList
+ protected IObservableList observableConcreteList;
+
+ // protected final List<?> transientList;
+
+ public CustomStyleObservableList(View view, String styleName, EditingDomain domain, EClass eClass, EStructuralFeature feature) {
+ super(getWrappedList(view, styleName, eClass, feature), domain, null, null);
+ this.eClass = eClass;
+ this.feature = feature;
+ this.styleName = styleName;
+ this.view = view;
+ this.domain = domain;
+ observableConcreteList = (IObservableList) concreteList;
+ styleExists = styleExists();
+
+ view.eAdapters().add(listener = new CustomStyleListener(view, feature, this, styleName));
+ }
+
+ @Override
+ public void commit(AbstractEditor editor) {
+ changing = true;
+ super.commit(editor);
+ changing = false;
+ }
+
+ protected boolean styleExists() {
+ // getNamedStyle may return a volatile result when CSS are available. We want a persistent element, so we should call directly view#getStyles()
+ // Call directly view.getStyles() instead of view.getNamedStyle()
+ for (Style style : (List<Style>) view.getStyles()) {
+ if (eClass.isInstance(style)) {
+ NamedStyle namedStyle = (NamedStyle) style;
+ if (styleName.equals(namedStyle.getName())) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean isStyleCreated() {
+ return getNamedStyle() != null;
+ }
+
+ protected NamedStyle getNamedStyle() {
+ return view.getNamedStyle(eClass, styleName);
+ }
+
+ private static IObservableList getWrappedList(View view, String styleName, EClass eClass, EStructuralFeature feature) {
+ NamedStyle style = view.getNamedStyle(eClass, styleName);
+
+ if (style != null) {
+ return EMFProperties.list(feature).observe(style);
+ }
+
+ // The style doesn't exist yet, we need to simulate it
+ // (With an empty list)
+ return new WritableList();
+ }
+
+ @Override
+ public Command getAddCommand(int index, Object value) {
+ return new AddCustomStyleListValueCommand(domain, view, styleName, eClass, feature, value, index);
+ }
+
+ @Override
+ public Command getAddCommand(Object value) {
+ return new AddCustomStyleListValueCommand(domain, view, styleName, eClass, feature, value);
+ }
+
+ @Override
+ public Command getAddAllCommand(Collection<?> values) {
+ return new AddAllCustomStyleListValueCommand(domain, view, styleName, eClass, feature, values);
+ }
+
+ @Override
+ public Command getAddAllCommand(int index, Collection<?> values) {
+ return new AddCustomStyleListValueCommand(domain, view, styleName, eClass, feature, values, index);
+ }
+
+ @Override
+ public Command getRemoveCommand(Object value) {
+ return new RemoveCustomStyleListValueCommand(domain, view, styleName, eClass, feature, value);
+ }
+
+ @Override
+ public Command getRemoveAllCommand(Collection<?> values) {
+ return new RemoveAllCustomStyleListValueCommand(domain, view, styleName, eClass, feature, values);
+ }
+
+ @Override
+ public Command getSetCommand(int index, Object value) {
+ return new SetCustomStyleListValueCommand(domain, view, styleName, eClass, feature, index, value);
+ }
+
+ @Override
+ public void handleChange(ChangeEvent event) {
+ // If the ListValueStyle has been created or removed, we need to resync
+ // the concrete list with it
+ if (styleExists != (styleExists = styleExists())) {
+ observableConcreteList.dispose();
+ concreteList = observableConcreteList = getConcreteList();
+ observableConcreteList.addChangeListener(this);
+ }
+
+ // If this observable is not the source of the change, the wrapped
+ // list should also be refreshed.
+ if (!changing) {
+ refreshCacheList();
+ }
+ }
+
+ protected IObservableList getConcreteList() {
+ return getWrappedList(view, styleName, eClass, feature);
+ }
+
+ @Override
+ public void dispose() {
+ if (isDisposed()) {
+ return;
+ }
+ if (listener != null) {
+ view.eAdapters().remove(listener);
+ listener.dispose();
+ listener = null;
+ }
+ observableConcreteList.dispose();
+ super.dispose();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveAllCustomStyleListValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveAllCustomStyleListValueCommand.java
index d98dbe6aae8..06217d676ee 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveAllCustomStyleListValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveAllCustomStyleListValueCommand.java
@@ -1,38 +1,38 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import java.util.Collection;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.RemoveCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class RemoveAllCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
-
- protected Collection<?> values;
-
- public RemoveAllCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass eClass, EStructuralFeature feature, Collection<?> values) {
- super(domain, view, styleName, eClass, feature);
- this.values = values;
- }
-
- @Override
- protected Command createCommand() {
- return RemoveCommand.create(domain, style, styleFeature, values);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.RemoveCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class RemoveAllCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
+
+ protected Collection<?> values;
+
+ public RemoveAllCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass eClass, EStructuralFeature feature, Collection<?> values) {
+ super(domain, view, styleName, eClass, feature);
+ this.values = values;
+ }
+
+ @Override
+ protected Command createCommand() {
+ return RemoveCommand.create(domain, style, styleFeature, values);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveCustomStyleListValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveCustomStyleListValueCommand.java
index 88ecb21bfa9..2a891da93e3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveCustomStyleListValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/RemoveCustomStyleListValueCommand.java
@@ -1,36 +1,36 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.RemoveCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class RemoveCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
-
- protected Object value;
-
- public RemoveCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass eClass, EStructuralFeature feature, Object value) {
- super(domain, view, styleName, eClass, feature);
- this.value = value;
- }
-
- @Override
- protected Command createCommand() {
- return RemoveCommand.create(domain, style, styleFeature, value);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.RemoveCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class RemoveCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
+
+ protected Object value;
+
+ public RemoveCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass eClass, EStructuralFeature feature, Object value) {
+ super(domain, view, styleName, eClass, feature);
+ this.value = value;
+ }
+
+ @Override
+ protected Command createCommand() {
+ return RemoveCommand.create(domain, style, styleFeature, value);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/SetCustomStyleListValueCommand.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/SetCustomStyleListValueCommand.java
index 4a4dee99e60..783cf37eba6 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/SetCustomStyleListValueCommand.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/databinding/custom/SetCustomStyleListValueCommand.java
@@ -1,39 +1,39 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
-
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.emf.edit.command.SetCommand;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public class SetCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
-
- private int index;
-
- private Object value;
-
- public SetCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass eClass, EStructuralFeature feature, int index, Object value) {
- super(domain, view, styleName, eClass, feature);
- this.index = index;
- this.value = value;
- }
-
- @Override
- protected Command createCommand() {
- return SetCommand.create(domain, style, styleFeature, value, index);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.edit.command.SetCommand;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public class SetCustomStyleListValueCommand extends AbstractCustomStyleListValueCommand {
+
+ private int index;
+
+ private Object value;
+
+ public SetCustomStyleListValueCommand(EditingDomain domain, View view, String styleName, EClass eClass, EStructuralFeature feature, int index, Object value) {
+ super(domain, view, styleName, eClass, feature);
+ this.index = index;
+ this.value = value;
+ }
+
+ @Override
+ protected Command createCommand() {
+ return SetCommand.create(domain, style, styleFeature, value, index);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ConnectionDecorationRegistry.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ConnectionDecorationRegistry.java
index fa3dfc1f784..0681794ad2e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ConnectionDecorationRegistry.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ConnectionDecorationRegistry.java
@@ -1,138 +1,138 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 521754
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.draw2d.RotatableDecoration;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
-
-/**
- * Registry for connection decoration declared throw <i>org.eclipse.papyrus.infra.gmfdiag.common.connectionDecoration</i> extension point.
- *
- * @author Mickaël ADAM
- * @since 3.1
- */
-public class ConnectionDecorationRegistry {
-
- /** The extension point id for connection decoration declaration. */
- public static final String EXTENSION_ID = Activator.ID + ".connectionDecoration";//$NON-NLS-1$
-
- /** the registry. */
- private volatile static ConnectionDecorationRegistry registry;
-
- /** The decoration map. */
- protected Map<String, Class<? extends RotatableDecoration>> decorationMap = null;
-
- /** The label map. */
- protected Map<String, String> labelMap = null;
-
- /**
- * Constructor.
- */
- private ConnectionDecorationRegistry() {
- super();
- }
-
- /**
- * @return the singleton instance of this registry
- */
- public static synchronized ConnectionDecorationRegistry getInstance() {
- if (null == registry) {
- registry = new ConnectionDecorationRegistry();
- registry.init();
- }
- return registry;
- }
-
- /**
- * Initialize the registry.
- */
- protected void init() {
- decorationMap = new HashMap<String, Class<? extends RotatableDecoration>>();
- labelMap = new HashMap<String, String>();
- IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
- for (IConfigurationElement element : elements) {
- String decorationName = element.getAttribute("name"); //$NON-NLS-1$
-
- String decorationClass = element.getAttribute("class"); //$NON-NLS-1$
- Class<? extends RotatableDecoration> loadClass = ClassLoaderHelper.loadClass(decorationClass, RotatableDecoration.class);
- if (null != loadClass) {
- decorationMap.put(decorationName, loadClass);
- }
-
- String decorationlabel = element.getAttribute("label"); //$NON-NLS-1$
- if (null != decorationlabel) {
- labelMap.put(decorationName, decorationlabel);
- }
- }
- }
-
- /**
- * Gets the decoration class.
- *
- * @param decorationName
- * the decoration name
- * @return the decoration class (null if not found)
- */
- public Class<? extends RotatableDecoration> getDecorationClass(final String decorationName) {
- Class<? extends RotatableDecoration> decorationClass = null;
- if (null != decorationName) {
- decorationClass = decorationMap.get(decorationName);
- }
- return decorationClass;
- }
-
- /**
- * @return the map of all available decorations.
- */
- public Map<String, Class<? extends RotatableDecoration>> getAvailableDecoration() {
- return decorationMap;
- }
-
- /**
- * Gets the decoration label.
- *
- * @param decorationName
- * the decoration name
- * @return the decoration label (null if not found)
- */
- public String getLabel(final String decorationName) {
- return labelMap.get(decorationName);
- }
-
- /**
- * Gets the decoration name.
- *
- * @param decorationLabel
- * the decoration label
- * @return the decoration name (null if not found)
- */
- public String getName(final String decorationLabel) {
- String name = null;
- try {
- name = labelMap.entrySet().stream()
- .filter(e -> e.getValue().equals(decorationLabel))
- .findFirst().get().getKey();
- } catch (Exception NoSuchElementException) {
- // Do nothing, return null if no element
- }
- return name;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 521754
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.RotatableDecoration;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+
+/**
+ * Registry for connection decoration declared throw <i>org.eclipse.papyrus.infra.gmfdiag.common.connectionDecoration</i> extension point.
+ *
+ * @author Mickaël ADAM
+ * @since 3.1
+ */
+public class ConnectionDecorationRegistry {
+
+ /** The extension point id for connection decoration declaration. */
+ public static final String EXTENSION_ID = Activator.ID + ".connectionDecoration";//$NON-NLS-1$
+
+ /** the registry. */
+ private volatile static ConnectionDecorationRegistry registry;
+
+ /** The decoration map. */
+ protected Map<String, Class<? extends RotatableDecoration>> decorationMap = null;
+
+ /** The label map. */
+ protected Map<String, String> labelMap = null;
+
+ /**
+ * Constructor.
+ */
+ private ConnectionDecorationRegistry() {
+ super();
+ }
+
+ /**
+ * @return the singleton instance of this registry
+ */
+ public static synchronized ConnectionDecorationRegistry getInstance() {
+ if (null == registry) {
+ registry = new ConnectionDecorationRegistry();
+ registry.init();
+ }
+ return registry;
+ }
+
+ /**
+ * Initialize the registry.
+ */
+ protected void init() {
+ decorationMap = new HashMap<String, Class<? extends RotatableDecoration>>();
+ labelMap = new HashMap<String, String>();
+ IConfigurationElement[] elements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+ for (IConfigurationElement element : elements) {
+ String decorationName = element.getAttribute("name"); //$NON-NLS-1$
+
+ String decorationClass = element.getAttribute("class"); //$NON-NLS-1$
+ Class<? extends RotatableDecoration> loadClass = ClassLoaderHelper.loadClass(decorationClass, RotatableDecoration.class);
+ if (null != loadClass) {
+ decorationMap.put(decorationName, loadClass);
+ }
+
+ String decorationlabel = element.getAttribute("label"); //$NON-NLS-1$
+ if (null != decorationlabel) {
+ labelMap.put(decorationName, decorationlabel);
+ }
+ }
+ }
+
+ /**
+ * Gets the decoration class.
+ *
+ * @param decorationName
+ * the decoration name
+ * @return the decoration class (null if not found)
+ */
+ public Class<? extends RotatableDecoration> getDecorationClass(final String decorationName) {
+ Class<? extends RotatableDecoration> decorationClass = null;
+ if (null != decorationName) {
+ decorationClass = decorationMap.get(decorationName);
+ }
+ return decorationClass;
+ }
+
+ /**
+ * @return the map of all available decorations.
+ */
+ public Map<String, Class<? extends RotatableDecoration>> getAvailableDecoration() {
+ return decorationMap;
+ }
+
+ /**
+ * Gets the decoration label.
+ *
+ * @param decorationName
+ * the decoration name
+ * @return the decoration label (null if not found)
+ */
+ public String getLabel(final String decorationName) {
+ return labelMap.get(decorationName);
+ }
+
+ /**
+ * Gets the decoration name.
+ *
+ * @param decorationLabel
+ * the decoration label
+ * @return the decoration name (null if not found)
+ */
+ public String getName(final String decorationLabel) {
+ String name = null;
+ try {
+ name = labelMap.entrySet().stream()
+ .filter(e -> e.getValue().equals(decorationLabel))
+ .findFirst().get().getKey();
+ } catch (Exception NoSuchElementException) {
+ // Do nothing, return null if no element
+ }
+ return name;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceDecoration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceDecoration.java
index a92850e7432..65ad5d5734f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceDecoration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceDecoration.java
@@ -1,70 +1,70 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import org.eclipse.emf.common.util.EList;
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions;
-import org.eclipse.papyrus.infra.services.decoration.util.Decoration.PreferedPosition;
-import org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration;
-import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
-
-/**
- * A Decorator for GMF Shapes, which is displayed when the graphical container is different
- * from the semantic container (i.e. highlight external references / imported elements)
- *
- * It is associated to the {@link ExternalReferenceMarker}
- *
- * @author Camille Letavernier
- */
-public class ExternalReferenceDecoration implements IDecorationSpecificFunctions {
-
- @Override
- public MarkChildren supportsMarkerPropagation() {
- // This marker should not be propagated
- return null;
- }
-
- @Override
- public IPapyrusDecoration markerPropagation(EList<IPapyrusDecoration> childDecorations) {
- // This marker should not be propagated
- return null;
- }
-
- @Override
- public ImageDescriptor getImageDescriptorForGE(IPapyrusMarker marker) {
- return org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor(Activator.ID, "icons/shortcut.gif"); //$NON-NLS-1$
- }
-
- @Override
- public ImageDescriptor getImageDescriptorForME(IPapyrusMarker marker) {
- // This decorator only applies to GMF elements
- return null;
- }
-
- @Override
- public PreferedPosition getPreferedPosition(IPapyrusMarker marker) {
- return PreferedPosition.NORTH_EAST;
- }
-
- @Override
- public String getMessage(IPapyrusMarker marker) {
- return "This element is imported";
- }
-
- @Override
- public int getPriority(IPapyrusMarker marker) {
- return 0;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.services.decoration.IDecorationSpecificFunctions;
+import org.eclipse.papyrus.infra.services.decoration.util.Decoration.PreferedPosition;
+import org.eclipse.papyrus.infra.services.decoration.util.IPapyrusDecoration;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+
+/**
+ * A Decorator for GMF Shapes, which is displayed when the graphical container is different
+ * from the semantic container (i.e. highlight external references / imported elements)
+ *
+ * It is associated to the {@link ExternalReferenceMarker}
+ *
+ * @author Camille Letavernier
+ */
+public class ExternalReferenceDecoration implements IDecorationSpecificFunctions {
+
+ @Override
+ public MarkChildren supportsMarkerPropagation() {
+ // This marker should not be propagated
+ return null;
+ }
+
+ @Override
+ public IPapyrusDecoration markerPropagation(EList<IPapyrusDecoration> childDecorations) {
+ // This marker should not be propagated
+ return null;
+ }
+
+ @Override
+ public ImageDescriptor getImageDescriptorForGE(IPapyrusMarker marker) {
+ return org.eclipse.papyrus.infra.widgets.Activator.getDefault().getImageDescriptor(Activator.ID, "icons/shortcut.gif"); //$NON-NLS-1$
+ }
+
+ @Override
+ public ImageDescriptor getImageDescriptorForME(IPapyrusMarker marker) {
+ // This decorator only applies to GMF elements
+ return null;
+ }
+
+ @Override
+ public PreferedPosition getPreferedPosition(IPapyrusMarker marker) {
+ return PreferedPosition.NORTH_EAST;
+ }
+
+ @Override
+ public String getMessage(IPapyrusMarker marker) {
+ return "This element is imported";
+ }
+
+ @Override
+ public int getPriority(IPapyrusMarker marker) {
+ return 0;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceMarker.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceMarker.java
index f37cd5fe044..28c354935b9 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceMarker.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/ExternalReferenceMarker.java
@@ -1,135 +1,135 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
-import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
-
-/**
- * An IPapyrusMarker for GMF Shapes, which is activated when the graphical container is different
- * from the semantic container (i.e. highlight external references / imported elements)
- *
- * This marker is volatile (created/deleted by EditPolicies on EditParts). It cannot be removed directly by the user
- *
- * @author Camille Letavernier
- *
- * @see {@link org.eclipse.papyrus.infra.gmfdiag.common.decoration.ExternalReferenceDecoration}
- * @see {@link org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalReferenceEditPolicy}
- */
-public class ExternalReferenceMarker implements IPapyrusMarker {
-
- public static final String MARKER_TYPE = "org.eclipse.papyrus.infra.gmfdiag.common.externalref"; //$NON-NLS-1$
-
- protected View notationElement;
-
- public ExternalReferenceMarker(View notationElement) {
- this.notationElement = notationElement;
- }
-
- @Override
- public Resource getResource() {
- return notationElement.eResource();
- }
-
- @Override
- public EObject getEObject() {
- return notationElement;
- }
-
- @Override
- public boolean exists() {
- return NotationHelper.isExternalRef(notationElement);
- }
-
- @Override
- public String getType() throws CoreException {
- return MARKER_TYPE;
- }
-
- @Override
- public String getTypeLabel() throws CoreException {
- return "External reference";
- }
-
- @Override
- public void delete() throws CoreException {
- // Do nothing: the user cannot manually remove the marker
- }
-
-
- // /
- // The marker doesn't have any attribute: default implementation does nothing
- // /
-
- @Override
- public Object getAttribute(String name) throws CoreException {
- return null;
- }
-
- @Override
- public String getAttribute(String name, String defaultValue) {
- return defaultValue;
- }
-
- @Override
- public boolean getAttribute(String name, boolean defaultValue) {
- return defaultValue;
- }
-
- @Override
- public int getAttribute(String name, int defaultValue) {
- return defaultValue;
- }
-
- @Override
- public Map<String, ?> getAttributes() throws CoreException {
- return Collections.emptyMap();
- }
-
- @Override
- public boolean isSubtypeOf(String type) throws CoreException {
- return false;
- }
-
- @Override
- public void setAttribute(String name, Object value) throws CoreException {
- // Nothing
- }
-
- @Override
- public void setAttribute(String name, String value) throws CoreException {
- // Nothing
- }
-
- @Override
- public void setAttribute(String name, boolean value) throws CoreException {
- // Nothing
- }
-
- @Override
- public void setAttribute(String name, int value) throws CoreException {
- // Nothing
- }
-
- @Override
- public void setAttributes(Map<String, ?> attributes) throws CoreException {
- // Nothing
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+
+/**
+ * An IPapyrusMarker for GMF Shapes, which is activated when the graphical container is different
+ * from the semantic container (i.e. highlight external references / imported elements)
+ *
+ * This marker is volatile (created/deleted by EditPolicies on EditParts). It cannot be removed directly by the user
+ *
+ * @author Camille Letavernier
+ *
+ * @see {@link org.eclipse.papyrus.infra.gmfdiag.common.decoration.ExternalReferenceDecoration}
+ * @see {@link org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalReferenceEditPolicy}
+ */
+public class ExternalReferenceMarker implements IPapyrusMarker {
+
+ public static final String MARKER_TYPE = "org.eclipse.papyrus.infra.gmfdiag.common.externalref"; //$NON-NLS-1$
+
+ protected View notationElement;
+
+ public ExternalReferenceMarker(View notationElement) {
+ this.notationElement = notationElement;
+ }
+
+ @Override
+ public Resource getResource() {
+ return notationElement.eResource();
+ }
+
+ @Override
+ public EObject getEObject() {
+ return notationElement;
+ }
+
+ @Override
+ public boolean exists() {
+ return NotationHelper.isExternalRef(notationElement);
+ }
+
+ @Override
+ public String getType() throws CoreException {
+ return MARKER_TYPE;
+ }
+
+ @Override
+ public String getTypeLabel() throws CoreException {
+ return "External reference";
+ }
+
+ @Override
+ public void delete() throws CoreException {
+ // Do nothing: the user cannot manually remove the marker
+ }
+
+
+ // /
+ // The marker doesn't have any attribute: default implementation does nothing
+ // /
+
+ @Override
+ public Object getAttribute(String name) throws CoreException {
+ return null;
+ }
+
+ @Override
+ public String getAttribute(String name, String defaultValue) {
+ return defaultValue;
+ }
+
+ @Override
+ public boolean getAttribute(String name, boolean defaultValue) {
+ return defaultValue;
+ }
+
+ @Override
+ public int getAttribute(String name, int defaultValue) {
+ return defaultValue;
+ }
+
+ @Override
+ public Map<String, ?> getAttributes() throws CoreException {
+ return Collections.emptyMap();
+ }
+
+ @Override
+ public boolean isSubtypeOf(String type) throws CoreException {
+ return false;
+ }
+
+ @Override
+ public void setAttribute(String name, Object value) throws CoreException {
+ // Nothing
+ }
+
+ @Override
+ public void setAttribute(String name, String value) throws CoreException {
+ // Nothing
+ }
+
+ @Override
+ public void setAttribute(String name, boolean value) throws CoreException {
+ // Nothing
+ }
+
+ @Override
+ public void setAttribute(String name, int value) throws CoreException {
+ // Nothing
+ }
+
+ @Override
+ public void setAttributes(Map<String, ?> attributes) throws CoreException {
+ // Nothing
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/OpenArrowConnectionDecoration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/OpenArrowConnectionDecoration.java
index 038e519e199..26ce5724f00 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/OpenArrowConnectionDecoration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/OpenArrowConnectionDecoration.java
@@ -1,61 +1,61 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import org.eclipse.draw2d.PolylineDecoration;
-
-/**
- * The <i>open_arrow</i> connection decoration.
- *
- * @author Mickael ADAM
- * @since 3.1
- */
-public class OpenArrowConnectionDecoration extends PolylineDecoration {
-
- /** Default X scale value. */
- private static final int DEFAULT_SCALE_X = 15;
-
- /** Default Y scale value. */
- private static final int DEFAULT_SCALE_Y = 5;
-
- /**
- * Constructor.
- */
- public OpenArrowConnectionDecoration() {
- init();
- }
-
- /**
- * Initialize the decoration.
- */
- protected void init() {
- setTemplate(PolylineDecoration.TRIANGLE_TIP);
- setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
- }
-
- /**
- * <pre>
- * Overridden to take into account of the line with in the scale (better representation).
- * </pre>
- *
- * {@inheritDoc}
- *
- * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
- */
- @Override
- public void setLineWidth(final int w) {
- setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
- super.setLineWidth(w);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import org.eclipse.draw2d.PolylineDecoration;
+
+/**
+ * The <i>open_arrow</i> connection decoration.
+ *
+ * @author Mickael ADAM
+ * @since 3.1
+ */
+public class OpenArrowConnectionDecoration extends PolylineDecoration {
+
+ /** Default X scale value. */
+ private static final int DEFAULT_SCALE_X = 15;
+
+ /** Default Y scale value. */
+ private static final int DEFAULT_SCALE_Y = 5;
+
+ /**
+ * Constructor.
+ */
+ public OpenArrowConnectionDecoration() {
+ init();
+ }
+
+ /**
+ * Initialize the decoration.
+ */
+ protected void init() {
+ setTemplate(PolylineDecoration.TRIANGLE_TIP);
+ setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
+ }
+
+ /**
+ * <pre>
+ * Overridden to take into account of the line with in the scale (better representation).
+ * </pre>
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
+ */
+ @Override
+ public void setLineWidth(final int w) {
+ setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
+ super.setLineWidth(w);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowEmptyConnectionDecoration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowEmptyConnectionDecoration.java
index d65794425bc..5c54d32ebb4 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowEmptyConnectionDecoration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowEmptyConnectionDecoration.java
@@ -1,65 +1,65 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.PolygonDecoration;
-
-/**
- * The <i>"solid_arrow_empty</i> connection decoration.
- *
- * @author Mickael ADAM
- * @since 3.1
- */
-public class SolidArrowEmptyConnectionDecoration extends PolygonDecoration {
-
- /** Default X scale value. */
- private static final int DEFAULT_SCALE_X = 15;
-
- /** Default Y scale value. */
- private static final int DEFAULT_SCALE_Y = 5;
-
- /**
- * Constructor.
- */
- public SolidArrowEmptyConnectionDecoration() {
- init();
- }
-
- /**
- * Initialize the decoration.
- */
- protected void init() {
- setTemplate(PolygonDecoration.TRIANGLE_TIP);
- setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
- // Not really empty... filled with white color.
- setFill(true);
- setBackgroundColor(ColorConstants.white);
- }
-
- /**
- * <pre>
- * Overridden to take into account of the line with in the scale (better representation).
- * </pre>
- *
- * {@inheritDoc}
- *
- * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
- */
- @Override
- public void setLineWidth(final int w) {
- setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
- super.setLineWidth(w);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.PolygonDecoration;
+
+/**
+ * The <i>"solid_arrow_empty</i> connection decoration.
+ *
+ * @author Mickael ADAM
+ * @since 3.1
+ */
+public class SolidArrowEmptyConnectionDecoration extends PolygonDecoration {
+
+ /** Default X scale value. */
+ private static final int DEFAULT_SCALE_X = 15;
+
+ /** Default Y scale value. */
+ private static final int DEFAULT_SCALE_Y = 5;
+
+ /**
+ * Constructor.
+ */
+ public SolidArrowEmptyConnectionDecoration() {
+ init();
+ }
+
+ /**
+ * Initialize the decoration.
+ */
+ protected void init() {
+ setTemplate(PolygonDecoration.TRIANGLE_TIP);
+ setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
+ // Not really empty... filled with white color.
+ setFill(true);
+ setBackgroundColor(ColorConstants.white);
+ }
+
+ /**
+ * <pre>
+ * Overridden to take into account of the line with in the scale (better representation).
+ * </pre>
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
+ */
+ @Override
+ public void setLineWidth(final int w) {
+ setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
+ super.setLineWidth(w);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowFilledConnectionDecoration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowFilledConnectionDecoration.java
index 3f5ecdd69be..669e880e963 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowFilledConnectionDecoration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidArrowFilledConnectionDecoration.java
@@ -1,63 +1,63 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import org.eclipse.draw2d.PolygonDecoration;
-
-/**
- * The <i>"solid_arrow_filled</i> connection decoration.
- *
- * @author Mickaël ADAM
- * @since 3.1
- */
-public class SolidArrowFilledConnectionDecoration extends PolygonDecoration {
-
- /** Default X scale value. */
- private static final int DEFAULT_SCALE_X = 15;
-
- /** Default Y scale value. */
- private static final int DEFAULT_SCALE_Y = 5;
-
-
- /**
- * Constructor.
- */
- public SolidArrowFilledConnectionDecoration() {
- init();
- }
-
- /**
- * Initialize the decoration.
- */
- protected void init() {
- setTemplate(PolygonDecoration.TRIANGLE_TIP);
- setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
- setFill(true);
- }
-
- /**
- * <pre>
- * Overridden to take into account of the line with in the scale (better representation).
- * </pre>
- *
- * {@inheritDoc}
- *
- * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
- */
- @Override
- public void setLineWidth(final int w) {
- setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
- super.setLineWidth(w);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import org.eclipse.draw2d.PolygonDecoration;
+
+/**
+ * The <i>"solid_arrow_filled</i> connection decoration.
+ *
+ * @author Mickaël ADAM
+ * @since 3.1
+ */
+public class SolidArrowFilledConnectionDecoration extends PolygonDecoration {
+
+ /** Default X scale value. */
+ private static final int DEFAULT_SCALE_X = 15;
+
+ /** Default Y scale value. */
+ private static final int DEFAULT_SCALE_Y = 5;
+
+
+ /**
+ * Constructor.
+ */
+ public SolidArrowFilledConnectionDecoration() {
+ init();
+ }
+
+ /**
+ * Initialize the decoration.
+ */
+ protected void init() {
+ setTemplate(PolygonDecoration.TRIANGLE_TIP);
+ setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
+ setFill(true);
+ }
+
+ /**
+ * <pre>
+ * Overridden to take into account of the line with in the scale (better representation).
+ * </pre>
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
+ */
+ @Override
+ public void setLineWidth(final int w) {
+ setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
+ super.setLineWidth(w);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondEmptyConnectionDecoration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondEmptyConnectionDecoration.java
index 6b78b3bfd19..9dfc8959924 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondEmptyConnectionDecoration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondEmptyConnectionDecoration.java
@@ -1,76 +1,76 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.PolygonDecoration;
-import org.eclipse.draw2d.geometry.PointList;
-
-/**
- * The <i>solid_diamond_empty</i> connection decoration.
- *
- * @author Mickaël ADAM
- * @since 3.1
- */
-public class SolidDiamondEmptyConnectionDecoration extends PolygonDecoration {
-
- /** Default X scale value. */
- private static final int DEFAULT_SCALE_X = 12;
-
- /** Default Y scale value. */
- private static final int DEFAULT_SCALE_Y = 6;
-
- /** The decoration list point */
- private static PointList decorationPointList = new PointList();
-
- static {
- decorationPointList.addPoint(0, 0);
- decorationPointList.addPoint(-1, 1);
- decorationPointList.addPoint(-2, 0);
- decorationPointList.addPoint(-1, -1);
- }
-
- /**
- * Constructor.
- */
- public SolidDiamondEmptyConnectionDecoration() {
- init();
- }
-
- /**
- * Initialize the decoration.
- */
- protected void init() {
- setTemplate(decorationPointList);
- setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
- // Not really empty... filled with white color.
- setFill(true);
- setBackgroundColor(ColorConstants.white);
- }
-
- /**
- * <pre>
- * Overridden to take into account of the line with in the scale (better representation).
- * </pre>
- *
- * {@inheritDoc}
- *
- * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
- */
- @Override
- public void setLineWidth(final int w) {
- setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
- super.setLineWidth(w);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.PolygonDecoration;
+import org.eclipse.draw2d.geometry.PointList;
+
+/**
+ * The <i>solid_diamond_empty</i> connection decoration.
+ *
+ * @author Mickaël ADAM
+ * @since 3.1
+ */
+public class SolidDiamondEmptyConnectionDecoration extends PolygonDecoration {
+
+ /** Default X scale value. */
+ private static final int DEFAULT_SCALE_X = 12;
+
+ /** Default Y scale value. */
+ private static final int DEFAULT_SCALE_Y = 6;
+
+ /** The decoration list point */
+ private static PointList decorationPointList = new PointList();
+
+ static {
+ decorationPointList.addPoint(0, 0);
+ decorationPointList.addPoint(-1, 1);
+ decorationPointList.addPoint(-2, 0);
+ decorationPointList.addPoint(-1, -1);
+ }
+
+ /**
+ * Constructor.
+ */
+ public SolidDiamondEmptyConnectionDecoration() {
+ init();
+ }
+
+ /**
+ * Initialize the decoration.
+ */
+ protected void init() {
+ setTemplate(decorationPointList);
+ setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
+ // Not really empty... filled with white color.
+ setFill(true);
+ setBackgroundColor(ColorConstants.white);
+ }
+
+ /**
+ * <pre>
+ * Overridden to take into account of the line with in the scale (better representation).
+ * </pre>
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
+ */
+ @Override
+ public void setLineWidth(final int w) {
+ setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
+ super.setLineWidth(w);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondFilledConnectionDecoration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondFilledConnectionDecoration.java
index 16562fec428..540982cd330 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondFilledConnectionDecoration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/decoration/SolidDiamondFilledConnectionDecoration.java
@@ -1,73 +1,73 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
-
-import org.eclipse.draw2d.PolygonDecoration;
-import org.eclipse.draw2d.geometry.PointList;
-
-/**
- * The <i>solid_diamond_filled</i> connection decoration.
- *
- * @author Mickaël ADAM
- * @since 3.1
- */
-public class SolidDiamondFilledConnectionDecoration extends PolygonDecoration {
-
- /** Default X scale value. */
- private static final int DEFAULT_SCALE_X = 12;
-
- /** Default Y scale value. */
- private static final int DEFAULT_SCALE_Y = 6;
-
- /** The decoration list point */
- private static PointList decorationPointList = new PointList();
-
- static {
- decorationPointList.addPoint(0, 0);
- decorationPointList.addPoint(-1, 1);
- decorationPointList.addPoint(-2, 0);
- decorationPointList.addPoint(-1, -1);
- }
-
- /**
- * Constructor.
- */
- public SolidDiamondFilledConnectionDecoration() {
- init();
- }
-
- /**
- * Initialize the decoration.
- */
- protected void init() {
- setTemplate(decorationPointList);
- setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
- setFill(true);
- }
-
- /**
- * <pre>
- * Overridden to take into account of the line with in the scale (better representation).
- * </pre>
- *
- * {@inheritDoc}
- *
- * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
- */
- @Override
- public void setLineWidth(final int w) {
- setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
- super.setLineWidth(w);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST, ALL4TEC 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:
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.decoration;
+
+import org.eclipse.draw2d.PolygonDecoration;
+import org.eclipse.draw2d.geometry.PointList;
+
+/**
+ * The <i>solid_diamond_filled</i> connection decoration.
+ *
+ * @author Mickaël ADAM
+ * @since 3.1
+ */
+public class SolidDiamondFilledConnectionDecoration extends PolygonDecoration {
+
+ /** Default X scale value. */
+ private static final int DEFAULT_SCALE_X = 12;
+
+ /** Default Y scale value. */
+ private static final int DEFAULT_SCALE_Y = 6;
+
+ /** The decoration list point */
+ private static PointList decorationPointList = new PointList();
+
+ static {
+ decorationPointList.addPoint(0, 0);
+ decorationPointList.addPoint(-1, 1);
+ decorationPointList.addPoint(-2, 0);
+ decorationPointList.addPoint(-1, -1);
+ }
+
+ /**
+ * Constructor.
+ */
+ public SolidDiamondFilledConnectionDecoration() {
+ init();
+ }
+
+ /**
+ * Initialize the decoration.
+ */
+ protected void init() {
+ setTemplate(decorationPointList);
+ setScale(DEFAULT_SCALE_X, DEFAULT_SCALE_Y);
+ setFill(true);
+ }
+
+ /**
+ * <pre>
+ * Overridden to take into account of the line with in the scale (better representation).
+ * </pre>
+ *
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.draw2d.Polyline#setLineWidth(int)
+ */
+ @Override
+ public void setLineWidth(final int w) {
+ setScale(DEFAULT_SCALE_X + w, DEFAULT_SCALE_Y + w);
+ super.setLineWidth(w);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java
index 227f21ffd9e..3b44a38176c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ConnectionEditPart.java
@@ -1,345 +1,345 @@
-/*****************************************************************************
- * Copyright (c) 2012, 2017 CEA LIST, ALL4TEC 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 515661, 522305
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.core.databinding.observable.ChangeEvent;
-import org.eclipse.core.databinding.observable.IChangeListener;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.Polyline;
-import org.eclipse.draw2d.RotatableDecoration;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EAnnotation;
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
-import org.eclipse.gmf.runtime.notation.Connector;
-import org.eclipse.gmf.runtime.notation.IntValueStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.StringValueStyle;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableValue;
-import org.eclipse.papyrus.infra.gmfdiag.common.decoration.ConnectionDecorationRegistry;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusConnectionEndEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.figure.edge.PapyrusEdgeFigure;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.NamedStyleProperties;
-import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.editparts.LinkLFConnectionNodeEditPart;
-import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
-
-
-/**
- * Abstract edit part for all connection nodes.
- */
-public abstract class ConnectionEditPart extends LinkLFConnectionNodeEditPart implements IPapyrusEditPart {
-
- /**
- * CSS property for the line style
- */
- protected static final String LINE_STYLE = "lineStyle"; //$NON-NLS-1$
-
- /**
- * Supported values of the CSS property lineStyle
- */
- protected static final String[] LINE_STYLE_VALUES = { "none", "hidden", "dotted", "dashed", "solid", "double" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
-
- /**
- * CSS property for the line dashes' length
- */
- protected static final String LINE_DASH_LENGTH = "lineDashLength"; //$NON-NLS-1$
-
- /**
- * CSS property for the length between line dashes
- */
- protected static final String LINE_DASH_GAP = "lineDashGap"; //$NON-NLS-1$
-
- /**
- * CSS property for the source decoration
- *
- * @since 3.1
- */
- public static final String SOURCE_DECORATION = "sourceDecoration"; //$NON-NLS-1$
-
- /**
- * CSS property for the target decoration
- *
- * @since 3.1
- */
- public static final String TARGET_DECORATION = "targetDecoration"; //$NON-NLS-1$
-
- /**
- * Supported values of the CSS property targetDecoration
- *
- * @since 3.1
- */
- public static final String[] DECORATION_VALUES = { "default", "none" }; //$NON-NLS-1$ //$NON-NLS-2$
-
- /**
- * Minimum length of dashes for dashed connectors
- */
- protected static final int LINE_DASH_MIN_LENGTH = 2;
-
- /**
- * Minimum length of the gaps between dashes
- */
- protected static final int LINE_GAP_MIN_LENGTH = 2;
-
- /** The source decoration Observable. */
- private IObservableValue sourceDecorationObservable;
-
- /** The target decoration Observable. */
- private IObservableValue targetDecorationObservable;
-
- /**
- * The namedStyle Listener. Refresh the edit part when handle a change.
- *
- * @since 3.1
- */
- private IChangeListener namedStyleListener = new IChangeListener() {
-
- @Override
- public void handleChange(ChangeEvent event) {
- refresh();
- }
-
- };
-
- /**
- * Constructor.
- */
- public ConnectionEditPart(View view) {
- super(view);
- }
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart#refresh()
- */
- @Override
- public void refresh() {
- super.refresh();
- IFigure figure = this.getFigure();
- Object model = this.getModel();
- if (figure instanceof PapyrusEdgeFigure && model instanceof Connector) {
- Connector connector = (Connector) model;
- PapyrusEdgeFigure edge = (PapyrusEdgeFigure) figure;
- // Reset the style
- edge.resetStyle();
- // Re-apply the CSS-defined style if any
- String lineStyle = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), LINE_STYLE));
- int lineDashLength = extract((IntValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), LINE_DASH_LENGTH));
- int lineDashGap = extract((IntValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), LINE_DASH_GAP));
- if (lineStyle != null) {
- setupLineStyle(edge, lineStyle, connector.getLineWidth(), lineDashLength < LINE_DASH_MIN_LENGTH ? LINE_DASH_MIN_LENGTH : lineDashLength, lineDashGap < LINE_GAP_MIN_LENGTH ? LINE_GAP_MIN_LENGTH : lineDashGap);
- }
-
- refreshConnectionDecoration(connector, edge);
- }
- }
-
- /**
- * Refresh the connection arrow decoration.
- *
- * @param connector
- * The notation connector
- * @param edge
- * the edge figure
- */
- private void refreshConnectionDecoration(final Connector connector, final PapyrusEdgeFigure edge) {
-
- // source refresh
- String sourceDecoration = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), SOURCE_DECORATION));
- if (null != sourceDecoration) {// not null
- edge.setSourceDecoration(getConnectionDecoration(sourceDecoration));
- }
-
- // target refresh
- String targetDecoration = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), TARGET_DECORATION));
- if (null != targetDecoration) {// not null
- edge.setTargetDecoration(getConnectionDecoration(targetDecoration));
- }
- }
-
- /**
- * Extracts the primitive value from the given style
- *
- * @param style
- * The style
- * @return The primitive value
- */
- private String extract(StringValueStyle style) {
- if (style == null || style.getStringValue() == null || style.getStringValue().isEmpty()) {
- return null;
- }
- return style.getStringValue();
- }
-
- /**
- * Extracts the primitive value from the given style
- *
- * @param style
- * The style
- * @return The primitive value
- */
- private int extract(IntValueStyle style) {
- if (style == null) {
- return 0;
- }
- return style.getIntValue();
- }
-
- /**
- * Setups the line style of the edge according to the given CSS style
- *
- * @param edge
- * The shape to setup
- * @param style
- * The CSS style
- * @param originalWidth
- * Original width of the connector
- * @param lineDashLength
- * Length of the dashes
- * @param lineDashGap
- * Length of the gap between dashes
- */
- private void setupLineStyle(PapyrusEdgeFigure edge, String style, int originalWidth, int lineDashLength, int lineDashGap) {
- if ("hidden".equals(style)) {//$NON-NLS-1$
- edge.setLineStyle(Graphics.LINE_SOLID);
- edge.setLineWidth(0);
- edge.setVisible(false);
- } else if ("dotted".equals(style)) {//$NON-NLS-1$
- edge.setLineStyle(Graphics.LINE_DOT);
- edge.setLineWidth(originalWidth);
- } else if ("dashed".equals(style)) {//$NON-NLS-1$
- edge.setLineStyle(Graphics.LINE_CUSTOM);
- edge.setLineWidth(originalWidth);
- edge.setLineDash(new int[] { lineDashLength, lineDashGap });
- } else if ("solid".equals(style)) {//$NON-NLS-1$
- edge.setLineStyle(Graphics.LINE_SOLID);
- edge.setLineWidth(originalWidth);
- } else if ("double".equals(style)) {//$NON-NLS-1$
- edge.setLineWidth(originalWidth * 2);
- } else if ("dash".equals(style)) {//$NON-NLS-1$
- edge.setLineStyle(Graphics.LINE_DASH);
- edge.setLineWidth(originalWidth);
- }
- }
-
- /**
- * Refresh the diagram when changing the label filters (Bug 491811: [CSS][Diagram] Connectors not refreshed after change of routing style (eg rectilinear->oblique))
- *
- * @since 2.0
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- protected void handleNotificationEvent(Notification notification) {
- super.handleNotificationEvent(notification);
-
- Object notifier = notification.getNotifier();
- Object oldValue = notification.getOldValue();
- // DO
- if (notifier instanceof EAnnotation) {
- if (((EAnnotation) notifier).getSource().equalsIgnoreCase(NamedStyleProperties.CSS_FORCE_VALUE)) {
- super.refresh();
- }
- }
- // UNDO
- else if (oldValue instanceof EAnnotation) {
- if (((EAnnotation) oldValue).getSource().equalsIgnoreCase(NamedStyleProperties.CSS_FORCE_VALUE)) {
- super.refresh();
- }
- }
- }
-
- /**
- * Gets the connection decoration in {@link ConnectionDecorationRegistry} for a String.
- *
- * @param arrowType
- * the arrow type
- * @return the {@link RotatableDecoration} use as connection decoration (null if not found)
- * @since 3.1
- */
- protected RotatableDecoration getConnectionDecoration(final String arrowType) {
- RotatableDecoration decoration = null;
- // Gets the decoration into the decoration registry
- Class<? extends RotatableDecoration> decorationClass = ConnectionDecorationRegistry.getInstance().getDecorationClass(arrowType);
- if (null != decorationClass) {
- // load the class
- decoration = ClassLoaderHelper.newInstance(decorationClass);
- // set the width
- if (decoration instanceof Polyline) {
- IMapMode mm = getMapMode();
- int width = getLineWidth();
- if (width < 0) {
- width = 1;
- }
- ((Polyline) decoration).setLineWidth(mm.DPtoLP(width));
- }
- }
-
- return decoration;
- }
-
- /**
- * Adds listener to handle named Style modifications.
- */
- @Override
- protected void addNotationalListeners() {
- super.addNotationalListeners();
-
- View view = (View) getModel();
- EditingDomain domain = EMFHelper.resolveEditingDomain(view);
-
- sourceDecorationObservable = new CustomStringStyleObservableValue(view, domain, SOURCE_DECORATION);
- sourceDecorationObservable.addChangeListener(namedStyleListener);
-
- targetDecorationObservable = new CustomStringStyleObservableValue(view, domain, TARGET_DECORATION);
- targetDecorationObservable.addChangeListener(namedStyleListener);
-
- }
-
- /**
- * Removes the notational listeners.
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeNotationalListeners()
- */
- @Override
- protected void removeNotationalListeners() {
- super.removeNotationalListeners();
- sourceDecorationObservable.dispose();
- targetDecorationObservable.dispose();
- }
-
- /**
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart#createDefaultEditPolicies()
- */
- @Override
- protected void createDefaultEditPolicies() {
- super.createDefaultEditPolicies();
- installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new PapyrusConnectionEndEditPolicy());
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart#refreshVisuals()
- */
- @Override
- protected void refreshVisuals() {
- super.refreshVisuals();
- refreshLineWidth();
- installRouter();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2017 CEA LIST, ALL4TEC 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - Bug 515661, 522305
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.Polyline;
+import org.eclipse.draw2d.RotatableDecoration;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EAnnotation;
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
+import org.eclipse.gmf.runtime.notation.Connector;
+import org.eclipse.gmf.runtime.notation.IntValueStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.StringValueStyle;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomStringStyleObservableValue;
+import org.eclipse.papyrus.infra.gmfdiag.common.decoration.ConnectionDecorationRegistry;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusConnectionEndEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.figure.edge.PapyrusEdgeFigure;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.NamedStyleProperties;
+import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.editparts.LinkLFConnectionNodeEditPart;
+import org.eclipse.papyrus.infra.tools.util.ClassLoaderHelper;
+
+
+/**
+ * Abstract edit part for all connection nodes.
+ */
+public abstract class ConnectionEditPart extends LinkLFConnectionNodeEditPart implements IPapyrusEditPart {
+
+ /**
+ * CSS property for the line style
+ */
+ protected static final String LINE_STYLE = "lineStyle"; //$NON-NLS-1$
+
+ /**
+ * Supported values of the CSS property lineStyle
+ */
+ protected static final String[] LINE_STYLE_VALUES = { "none", "hidden", "dotted", "dashed", "solid", "double" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+
+ /**
+ * CSS property for the line dashes' length
+ */
+ protected static final String LINE_DASH_LENGTH = "lineDashLength"; //$NON-NLS-1$
+
+ /**
+ * CSS property for the length between line dashes
+ */
+ protected static final String LINE_DASH_GAP = "lineDashGap"; //$NON-NLS-1$
+
+ /**
+ * CSS property for the source decoration
+ *
+ * @since 3.1
+ */
+ public static final String SOURCE_DECORATION = "sourceDecoration"; //$NON-NLS-1$
+
+ /**
+ * CSS property for the target decoration
+ *
+ * @since 3.1
+ */
+ public static final String TARGET_DECORATION = "targetDecoration"; //$NON-NLS-1$
+
+ /**
+ * Supported values of the CSS property targetDecoration
+ *
+ * @since 3.1
+ */
+ public static final String[] DECORATION_VALUES = { "default", "none" }; //$NON-NLS-1$ //$NON-NLS-2$
+
+ /**
+ * Minimum length of dashes for dashed connectors
+ */
+ protected static final int LINE_DASH_MIN_LENGTH = 2;
+
+ /**
+ * Minimum length of the gaps between dashes
+ */
+ protected static final int LINE_GAP_MIN_LENGTH = 2;
+
+ /** The source decoration Observable. */
+ private IObservableValue sourceDecorationObservable;
+
+ /** The target decoration Observable. */
+ private IObservableValue targetDecorationObservable;
+
+ /**
+ * The namedStyle Listener. Refresh the edit part when handle a change.
+ *
+ * @since 3.1
+ */
+ private IChangeListener namedStyleListener = new IChangeListener() {
+
+ @Override
+ public void handleChange(ChangeEvent event) {
+ refresh();
+ }
+
+ };
+
+ /**
+ * Constructor.
+ */
+ public ConnectionEditPart(View view) {
+ super(view);
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart#refresh()
+ */
+ @Override
+ public void refresh() {
+ super.refresh();
+ IFigure figure = this.getFigure();
+ Object model = this.getModel();
+ if (figure instanceof PapyrusEdgeFigure && model instanceof Connector) {
+ Connector connector = (Connector) model;
+ PapyrusEdgeFigure edge = (PapyrusEdgeFigure) figure;
+ // Reset the style
+ edge.resetStyle();
+ // Re-apply the CSS-defined style if any
+ String lineStyle = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), LINE_STYLE));
+ int lineDashLength = extract((IntValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), LINE_DASH_LENGTH));
+ int lineDashGap = extract((IntValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getIntValueStyle(), LINE_DASH_GAP));
+ if (lineStyle != null) {
+ setupLineStyle(edge, lineStyle, connector.getLineWidth(), lineDashLength < LINE_DASH_MIN_LENGTH ? LINE_DASH_MIN_LENGTH : lineDashLength, lineDashGap < LINE_GAP_MIN_LENGTH ? LINE_GAP_MIN_LENGTH : lineDashGap);
+ }
+
+ refreshConnectionDecoration(connector, edge);
+ }
+ }
+
+ /**
+ * Refresh the connection arrow decoration.
+ *
+ * @param connector
+ * The notation connector
+ * @param edge
+ * the edge figure
+ */
+ private void refreshConnectionDecoration(final Connector connector, final PapyrusEdgeFigure edge) {
+
+ // source refresh
+ String sourceDecoration = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), SOURCE_DECORATION));
+ if (null != sourceDecoration) {// not null
+ edge.setSourceDecoration(getConnectionDecoration(sourceDecoration));
+ }
+
+ // target refresh
+ String targetDecoration = extract((StringValueStyle) connector.getNamedStyle(NotationPackage.eINSTANCE.getStringValueStyle(), TARGET_DECORATION));
+ if (null != targetDecoration) {// not null
+ edge.setTargetDecoration(getConnectionDecoration(targetDecoration));
+ }
+ }
+
+ /**
+ * Extracts the primitive value from the given style
+ *
+ * @param style
+ * The style
+ * @return The primitive value
+ */
+ private String extract(StringValueStyle style) {
+ if (style == null || style.getStringValue() == null || style.getStringValue().isEmpty()) {
+ return null;
+ }
+ return style.getStringValue();
+ }
+
+ /**
+ * Extracts the primitive value from the given style
+ *
+ * @param style
+ * The style
+ * @return The primitive value
+ */
+ private int extract(IntValueStyle style) {
+ if (style == null) {
+ return 0;
+ }
+ return style.getIntValue();
+ }
+
+ /**
+ * Setups the line style of the edge according to the given CSS style
+ *
+ * @param edge
+ * The shape to setup
+ * @param style
+ * The CSS style
+ * @param originalWidth
+ * Original width of the connector
+ * @param lineDashLength
+ * Length of the dashes
+ * @param lineDashGap
+ * Length of the gap between dashes
+ */
+ private void setupLineStyle(PapyrusEdgeFigure edge, String style, int originalWidth, int lineDashLength, int lineDashGap) {
+ if ("hidden".equals(style)) {//$NON-NLS-1$
+ edge.setLineStyle(Graphics.LINE_SOLID);
+ edge.setLineWidth(0);
+ edge.setVisible(false);
+ } else if ("dotted".equals(style)) {//$NON-NLS-1$
+ edge.setLineStyle(Graphics.LINE_DOT);
+ edge.setLineWidth(originalWidth);
+ } else if ("dashed".equals(style)) {//$NON-NLS-1$
+ edge.setLineStyle(Graphics.LINE_CUSTOM);
+ edge.setLineWidth(originalWidth);
+ edge.setLineDash(new int[] { lineDashLength, lineDashGap });
+ } else if ("solid".equals(style)) {//$NON-NLS-1$
+ edge.setLineStyle(Graphics.LINE_SOLID);
+ edge.setLineWidth(originalWidth);
+ } else if ("double".equals(style)) {//$NON-NLS-1$
+ edge.setLineWidth(originalWidth * 2);
+ } else if ("dash".equals(style)) {//$NON-NLS-1$
+ edge.setLineStyle(Graphics.LINE_DASH);
+ edge.setLineWidth(originalWidth);
+ }
+ }
+
+ /**
+ * Refresh the diagram when changing the label filters (Bug 491811: [CSS][Diagram] Connectors not refreshed after change of routing style (eg rectilinear->oblique))
+ *
+ * @since 2.0
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart#handleNotificationEvent(org.eclipse.emf.common.notify.Notification)
+ *
+ * @param notification
+ */
+ @Override
+ protected void handleNotificationEvent(Notification notification) {
+ super.handleNotificationEvent(notification);
+
+ Object notifier = notification.getNotifier();
+ Object oldValue = notification.getOldValue();
+ // DO
+ if (notifier instanceof EAnnotation) {
+ if (((EAnnotation) notifier).getSource().equalsIgnoreCase(NamedStyleProperties.CSS_FORCE_VALUE)) {
+ super.refresh();
+ }
+ }
+ // UNDO
+ else if (oldValue instanceof EAnnotation) {
+ if (((EAnnotation) oldValue).getSource().equalsIgnoreCase(NamedStyleProperties.CSS_FORCE_VALUE)) {
+ super.refresh();
+ }
+ }
+ }
+
+ /**
+ * Gets the connection decoration in {@link ConnectionDecorationRegistry} for a String.
+ *
+ * @param arrowType
+ * the arrow type
+ * @return the {@link RotatableDecoration} use as connection decoration (null if not found)
+ * @since 3.1
+ */
+ protected RotatableDecoration getConnectionDecoration(final String arrowType) {
+ RotatableDecoration decoration = null;
+ // Gets the decoration into the decoration registry
+ Class<? extends RotatableDecoration> decorationClass = ConnectionDecorationRegistry.getInstance().getDecorationClass(arrowType);
+ if (null != decorationClass) {
+ // load the class
+ decoration = ClassLoaderHelper.newInstance(decorationClass);
+ // set the width
+ if (decoration instanceof Polyline) {
+ IMapMode mm = getMapMode();
+ int width = getLineWidth();
+ if (width < 0) {
+ width = 1;
+ }
+ ((Polyline) decoration).setLineWidth(mm.DPtoLP(width));
+ }
+ }
+
+ return decoration;
+ }
+
+ /**
+ * Adds listener to handle named Style modifications.
+ */
+ @Override
+ protected void addNotationalListeners() {
+ super.addNotationalListeners();
+
+ View view = (View) getModel();
+ EditingDomain domain = EMFHelper.resolveEditingDomain(view);
+
+ sourceDecorationObservable = new CustomStringStyleObservableValue(view, domain, SOURCE_DECORATION);
+ sourceDecorationObservable.addChangeListener(namedStyleListener);
+
+ targetDecorationObservable = new CustomStringStyleObservableValue(view, domain, TARGET_DECORATION);
+ targetDecorationObservable.addChangeListener(namedStyleListener);
+
+ }
+
+ /**
+ * Removes the notational listeners.
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart#removeNotationalListeners()
+ */
+ @Override
+ protected void removeNotationalListeners() {
+ super.removeNotationalListeners();
+ sourceDecorationObservable.dispose();
+ targetDecorationObservable.dispose();
+ }
+
+ /**
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionNodeEditPart#createDefaultEditPolicies()
+ */
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ installEditPolicy(EditPolicy.CONNECTION_ENDPOINTS_ROLE, new PapyrusConnectionEndEditPolicy());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart#refreshVisuals()
+ */
+ @Override
+ protected void refreshVisuals() {
+ super.refreshVisuals();
+ refreshLineWidth();
+ installRouter();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IBorderItemWithLocator.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IBorderItemWithLocator.java
index fe1f573cccb..ac7d1726751 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IBorderItemWithLocator.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IBorderItemWithLocator.java
@@ -1,27 +1,27 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
-
-/**
- * @author Patrick Tessier
- *
- */
-public interface IBorderItemWithLocator {
-
- public IBorderItemLocator getNewBorderItemLocator(IFigure mainFigure);
-
-}
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+
+/**
+ * @author Patrick Tessier
+ *
+ */
+public interface IBorderItemWithLocator {
+
+ public IBorderItemLocator getNewBorderItemLocator(IFigure mainFigure);
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IPapyrusEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IPapyrusEditPart.java
index 9212c5a0fbb..49b3bc7d07e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IPapyrusEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IPapyrusEditPart.java
@@ -1,32 +1,32 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.draw2d.IFigure;
-
-/**
- * This is an editPart in which we can get primaryShape to obtain the figure
- *
- */
-public interface IPapyrusEditPart {
-
- /**
- * <p>
- * Returns the primary shape being the View of this edit part.
- * </p>
- * <b>Warning</b> It should never return <code>null</code>
- *
- * @return the primary shape associated to this edit part.
- */
- public IFigure getPrimaryShape();
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ /*****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+import org.eclipse.draw2d.IFigure;
+
+/**
+ * This is an editPart in which we can get primaryShape to obtain the figure
+ *
+ */
+public interface IPapyrusEditPart {
+
+ /**
+ * <p>
+ * Returns the primary shape being the View of this edit part.
+ * </p>
+ * <b>Warning</b> It should never return <code>null</code>
+ *
+ * @return the primary shape associated to this edit part.
+ */
+ public IFigure getPrimaryShape();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IShapeCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IShapeCompartmentEditPart.java
index 8eb3538f523..bad0d17acbc 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IShapeCompartmentEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/IShapeCompartmentEditPart.java
@@ -1,26 +1,26 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-/**
- * Interface for Edit Parts that are responsible of the display of a shape.
- * <p>
- * This is currently only a marker interface, no method are planned to be added yet.
- * </p>
- */
-public interface IShapeCompartmentEditPart {
-
- /** type given to the view model of this edit part */
- public static final String VIEW_TYPE = "compartment_shape_display";
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+/**
+ * Interface for Edit Parts that are responsible of the display of a shape.
+ * <p>
+ * This is currently only a marker interface, no method are planned to be added yet.
+ * </p>
+ */
+public interface IShapeCompartmentEditPart {
+
+ /** type given to the view model of this edit part */
+ public static final String VIEW_TYPE = "compartment_shape_display";
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java
index f93afd2aa94..605425d43a3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/PapyrusCompartmentEditPart.java
@@ -1,46 +1,46 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
-
-
-public abstract class PapyrusCompartmentEditPart extends CompartmentEditPart {
-
- public PapyrusCompartmentEditPart(EObject model) {
- super(model);
- }
-
- @Override
- public boolean isSelectable() {
- return false;
- }
-
- /**
- * Provide access to isSelectable operation from super class, allows sub-classes to restore original behavior
- *
- * @return original method of superclass
- */
- public boolean isSelectableOrig() {
- return super.isSelectable();
- }
-
- @Override
- protected void createDefaultEditPolicies() {
- super.createDefaultEditPolicies();
- installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
+
+
+public abstract class PapyrusCompartmentEditPart extends CompartmentEditPart {
+
+ public PapyrusCompartmentEditPart(EObject model) {
+ super(model);
+ }
+
+ @Override
+ public boolean isSelectable() {
+ return false;
+ }
+
+ /**
+ * Provide access to isSelectable operation from super class, allows sub-classes to restore original behavior
+ *
+ * @return original method of superclass
+ */
+ public boolean isSelectableOrig() {
+ return super.isSelectable();
+ }
+
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ResizeableListCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ResizeableListCompartmentEditPart.java
index 8a963b82dff..97acc1bf075 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ResizeableListCompartmentEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/ResizeableListCompartmentEditPart.java
@@ -1,87 +1,87 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
-
-public abstract class ResizeableListCompartmentEditPart extends ListCompartmentEditPart {
-
- public ResizeableListCompartmentEditPart(EObject model) {
- super(model);
- }
-
- /**
- * refresh the bounds
- */
- protected void refreshBounds() {
- int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
- int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
- Dimension size = new Dimension(width, height);
- int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
- int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
- Point loc = new Point(x, y);
- ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(loc, size));
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- protected void refreshVisuals() {
- super.refreshVisuals();
- refreshBounds();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- protected void handleNotificationEvent(Notification notification) {
- Object feature = notification.getFeature();
- if (NotationPackage.eINSTANCE.getSize_Width().equals(feature) || NotationPackage.eINSTANCE.getSize_Height().equals(feature) || NotationPackage.eINSTANCE.getLocation_X().equals(feature) || NotationPackage.eINSTANCE.getLocation_Y().equals(feature)) {
- refreshBounds();
- }
- if (resolveSemanticElement() != null) {
- super.handleNotificationEvent(notification);
- }
- // Refresh needed upon moving attributes in new compartments
- if (Notification.ADD == notification.getEventType()) {
- DiagramHelper.refresh(this, true);
- }
- }
-
- @Override
- public boolean isSelectable() {
- return false;
- }
-
- @Override
- protected void createDefaultEditPolicies() {
- super.createDefaultEditPolicies();
-
- installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ListCompartmentEditPart;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.BorderDisplayEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.DiagramHelper;
+
+public abstract class ResizeableListCompartmentEditPart extends ListCompartmentEditPart {
+
+ public ResizeableListCompartmentEditPart(EObject model) {
+ super(model);
+ }
+
+ /**
+ * refresh the bounds
+ */
+ protected void refreshBounds() {
+ int width = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Width())).intValue();
+ int height = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getSize_Height())).intValue();
+ Dimension size = new Dimension(width, height);
+ int x = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_X())).intValue();
+ int y = ((Integer) getStructuralFeatureValue(NotationPackage.eINSTANCE.getLocation_Y())).intValue();
+ Point loc = new Point(x, y);
+ ((GraphicalEditPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(loc, size));
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ protected void refreshVisuals() {
+ super.refreshVisuals();
+ refreshBounds();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ protected void handleNotificationEvent(Notification notification) {
+ Object feature = notification.getFeature();
+ if (NotationPackage.eINSTANCE.getSize_Width().equals(feature) || NotationPackage.eINSTANCE.getSize_Height().equals(feature) || NotationPackage.eINSTANCE.getLocation_X().equals(feature) || NotationPackage.eINSTANCE.getLocation_Y().equals(feature)) {
+ refreshBounds();
+ }
+ if (resolveSemanticElement() != null) {
+ super.handleNotificationEvent(notification);
+ }
+ // Refresh needed upon moving attributes in new compartments
+ if (Notification.ADD == notification.getEventType()) {
+ DiagramHelper.refresh(this, true);
+ }
+ }
+
+ @Override
+ public boolean isSelectable() {
+ return false;
+ }
+
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+
+ installEditPolicy(BorderDisplayEditPolicy.BORDER_DISPLAY_EDITPOLICY, new BorderDisplayEditPolicy());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/XYLayoutShapeCompartmentEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/XYLayoutShapeCompartmentEditPart.java
index 3848f4da4c1..a60191ac0e0 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/XYLayoutShapeCompartmentEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpart/XYLayoutShapeCompartmentEditPart.java
@@ -1,55 +1,55 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
-
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.LinkLFShapeCompartmentEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusPopupBarEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.XYLayoutWithConstrainedResizedEditPolicy;
-
-/**
- *
- * This compartment edit part must be used for CompartmentEditPart with XYlayoutEditPolicy
- * This class replace default editpolicy by ours 424942: [Diagram] Papyrus shall ease resizing of model elements owning children
- *
- */
-public class XYLayoutShapeCompartmentEditPart extends LinkLFShapeCompartmentEditPart {
-
-
- /**
- *
- * Constructor.
- *
- * @param view
- */
- public XYLayoutShapeCompartmentEditPart(final View view) {
- super(view);
- }
-
- /**
- *
- * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart#createDefaultEditPolicies()
- *
- */
- @Override
- protected void createDefaultEditPolicies() {
- super.createDefaultEditPolicies();
- installEditPolicy(EditPolicy.LAYOUT_ROLE, new XYLayoutWithConstrainedResizedEditPolicy());
- // Override GMF's popup bar policy
- installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new PapyrusPopupBarEditPolicy());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpart;
+
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.EditPolicyRoles;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.tooling.runtime.linklf.LinkLFShapeCompartmentEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.PapyrusPopupBarEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.XYLayoutWithConstrainedResizedEditPolicy;
+
+/**
+ *
+ * This compartment edit part must be used for CompartmentEditPart with XYlayoutEditPolicy
+ * This class replace default editpolicy by ours 424942: [Diagram] Papyrus shall ease resizing of model elements owning children
+ *
+ */
+public class XYLayoutShapeCompartmentEditPart extends LinkLFShapeCompartmentEditPart {
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param view
+ */
+ public XYLayoutShapeCompartmentEditPart(final View view) {
+ super(view);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeCompartmentEditPart#createDefaultEditPolicies()
+ *
+ */
+ @Override
+ protected void createDefaultEditPolicies() {
+ super.createDefaultEditPolicies();
+ installEditPolicy(EditPolicy.LAYOUT_ROLE, new XYLayoutWithConstrainedResizedEditPolicy());
+ // Override GMF's popup bar policy
+ installEditPolicy(EditPolicyRoles.POPUPBAR_ROLE, new PapyrusPopupBarEditPolicy());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/DefaultCompartmentSemanticEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/DefaultCompartmentSemanticEditPolicy.java
index 273e9768171..e64b374bae0 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/DefaultCompartmentSemanticEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/DefaultCompartmentSemanticEditPolicy.java
@@ -1,46 +1,46 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
-import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
-import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
-import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
-
-
-public class DefaultCompartmentSemanticEditPolicy extends DefaultSemanticEditPolicy {
-
-
- protected Command getMoveCommand(MoveRequest req) {
- EObject targetCEObject = req.getTargetContainer();
- if (targetCEObject != null) {
- IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetCEObject);
- if (provider != null) {
- ICommand moveCommand = provider.getEditCommand(req);
- if (moveCommand != null) {
- return new ICommandProxy(moveCommand);
- }
- }
- return UnexecutableCommand.INSTANCE;
- } else {
- return getGEFWrapper(new MoveElementsCommand(req));
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.emf.type.core.commands.MoveElementsCommand;
+import org.eclipse.gmf.runtime.emf.type.core.requests.MoveRequest;
+import org.eclipse.papyrus.infra.services.edit.service.ElementEditServiceUtils;
+import org.eclipse.papyrus.infra.services.edit.service.IElementEditService;
+
+
+public class DefaultCompartmentSemanticEditPolicy extends DefaultSemanticEditPolicy {
+
+
+ protected Command getMoveCommand(MoveRequest req) {
+ EObject targetCEObject = req.getTargetContainer();
+ if (targetCEObject != null) {
+ IElementEditService provider = ElementEditServiceUtils.getCommandProvider(targetCEObject);
+ if (provider != null) {
+ ICommand moveCommand = provider.getEditCommand(req);
+ if (moveCommand != null) {
+ return new ICommandProxy(moveCommand);
+ }
+ }
+ return UnexecutableCommand.INSTANCE;
+ } else {
+ return getGEFWrapper(new MoveElementsCommand(req));
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/EdgeWithNoSemanticElementRepresentationImpl.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/EdgeWithNoSemanticElementRepresentationImpl.java
index a10e86105e8..d614b343049 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/EdgeWithNoSemanticElementRepresentationImpl.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/EdgeWithNoSemanticElementRepresentationImpl.java
@@ -1,121 +1,121 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.impl.EObjectImpl;
-
-/**
- *
- * @author Vincent Lorenzo
- * An eobject class used to represent a link with no semantic element
- */
-public class EdgeWithNoSemanticElementRepresentationImpl extends EObjectImpl {
-
- /**
- * the semantic hint for the represented element
- */
- protected String semanticHint;
-
- /**
- * the source of the link
- */
- protected final EObject source;
-
- /**
- * the target of the link
- */
- protected final EObject target;
-
- /**
- *
- * Constructor.
- *
- * @param source
- * the source of the link
- * @param target
- * the target of the link
- * @param semanticHint
- * the semantic hint for the represented element
- */
- public EdgeWithNoSemanticElementRepresentationImpl(final EObject source, final EObject target, final String semanticHint) {
- this.source = source;
- this.target = target;
- this.semanticHint = semanticHint;
- }
-
- /**
- *
- * @return
- * the source of the represented link
- */
- public EObject getSource() {
- return source;
- }
-
- /**
- *
- * @return
- * the target of the represented link
- */
- public EObject getTarget() {
- return target;
- }
-
- /**
- *
- * @return
- * a view for this link
- */
- public String getSemanticHint() {
- return semanticHint;
- }
-
- /**
- * Calculate the hashcode in order to allows to have the same hashcode for 2 {@link EdgeWithNoSemanticElementRepresentationImpl} with the same
- * field values.
- *
- * @see java.lang.Object#hashCode()
- *
- * @return
- * the hashcode
- */
- @Override
- public int hashCode() {
- int result = 1;
- result = result + ((this.target == null) ? 0 : this.target.hashCode());
- result = result + 7 * ((this.source == null) ? 0 : this.source.hashCode());
- result = result + 11 * ((this.semanticHint == null) ? 0 : this.semanticHint.hashCode());
- return result;
- }
-
- /**
- *
- * @see java.lang.Object#equals(java.lang.Object)
- *
- * @param obj
- * an object
- * @return
- * <code>true</code> if this object is the same than the other one
- */
- @Override
- public boolean equals(final Object obj) {
- if (obj instanceof EdgeWithNoSemanticElementRepresentationImpl) {
- final EdgeWithNoSemanticElementRepresentationImpl otherLink = (EdgeWithNoSemanticElementRepresentationImpl) obj;
- return this.source == otherLink.getSource() && this.target == otherLink.getTarget() && this.semanticHint.equals(otherLink.getSemanticHint());
- }
- return false;
- }
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.impl.EObjectImpl;
+
+/**
+ *
+ * @author Vincent Lorenzo
+ * An eobject class used to represent a link with no semantic element
+ */
+public class EdgeWithNoSemanticElementRepresentationImpl extends EObjectImpl {
+
+ /**
+ * the semantic hint for the represented element
+ */
+ protected String semanticHint;
+
+ /**
+ * the source of the link
+ */
+ protected final EObject source;
+
+ /**
+ * the target of the link
+ */
+ protected final EObject target;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param source
+ * the source of the link
+ * @param target
+ * the target of the link
+ * @param semanticHint
+ * the semantic hint for the represented element
+ */
+ public EdgeWithNoSemanticElementRepresentationImpl(final EObject source, final EObject target, final String semanticHint) {
+ this.source = source;
+ this.target = target;
+ this.semanticHint = semanticHint;
+ }
+
+ /**
+ *
+ * @return
+ * the source of the represented link
+ */
+ public EObject getSource() {
+ return source;
+ }
+
+ /**
+ *
+ * @return
+ * the target of the represented link
+ */
+ public EObject getTarget() {
+ return target;
+ }
+
+ /**
+ *
+ * @return
+ * a view for this link
+ */
+ public String getSemanticHint() {
+ return semanticHint;
+ }
+
+ /**
+ * Calculate the hashcode in order to allows to have the same hashcode for 2 {@link EdgeWithNoSemanticElementRepresentationImpl} with the same
+ * field values.
+ *
+ * @see java.lang.Object#hashCode()
+ *
+ * @return
+ * the hashcode
+ */
+ @Override
+ public int hashCode() {
+ int result = 1;
+ result = result + ((this.target == null) ? 0 : this.target.hashCode());
+ result = result + 7 * ((this.source == null) ? 0 : this.source.hashCode());
+ result = result + 11 * ((this.semanticHint == null) ? 0 : this.semanticHint.hashCode());
+ return result;
+ }
+
+ /**
+ *
+ * @see java.lang.Object#equals(java.lang.Object)
+ *
+ * @param obj
+ * an object
+ * @return
+ * <code>true</code> if this object is the same than the other one
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ if (obj instanceof EdgeWithNoSemanticElementRepresentationImpl) {
+ final EdgeWithNoSemanticElementRepresentationImpl otherLink = (EdgeWithNoSemanticElementRepresentationImpl) obj;
+ return this.source == otherLink.getSource() && this.target == otherLink.getTarget() && this.semanticHint.equals(otherLink.getSemanticHint());
+ }
+ return false;
+ }
} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ExternalReferenceEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ExternalReferenceEditPolicy.java
index 852405fd45a..c5239271e0c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ExternalReferenceEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ExternalReferenceEditPolicy.java
@@ -1,125 +1,125 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.gmfdiag.common.decoration.ExternalReferenceMarker;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
-import org.eclipse.papyrus.infra.services.decoration.DecorationService;
-import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
-
-/**
- * A generic EditPolicy which applies {@link ExternalReferenceMarker} to EditParts when they have been imported
- * (According to {@link NotationHelper#isExternalRef(View)}
- *
- * @author Camille Letavernier
- *
- */
-// Rely on the GraphicalEditPolicyEx, which is less expensive than adding a listener to detect changes in the containment tree
-@SuppressWarnings("restriction")
-public class ExternalReferenceEditPolicy extends GraphicalEditPolicyEx {
-
- /**
- * The Edit Policy Role/ID
- */
- public static final Object EDIT_POLICY_ROLE = Activator.ID + ".externalReferenceDecorator"; //$NON-NLS-1$
-
- /**
- * Last known value for isExternalReference
- */
- protected boolean isExternalReference = false;
-
- protected DecorationService decorationService;
-
- protected IPapyrusMarker marker;
-
- protected Adapter listener;
-
- @Override
- public void activate() {
- super.activate();
-
- try {
- decorationService = ServiceUtilsForEditPart.getInstance().getService(DecorationService.class, getHost());
- refresh();
- } catch (ServiceException ex) {
- // Ignored; do nothing
- }
- }
-
- @Override
- public void refresh() {
- if (getView() == null) {
- return;
- }
- if (decorationService == null) {
- return;
- }
-
- // Add or remove the decoration when the current value is different from the last known value
- if (isExternalRef(getView()) != isExternalReference) {
- isExternalReference = !isExternalReference;
- if (isExternalReference) {
- decorationService.addDecoration(getMarker(), getView());
- } else {
- decorationService.removeDecoration(getMarker().toString());
- }
- // We need to call refresh again, so that the decorator gets display.
- // We shouldn't end up with a StackOverFlow, because we arrive here only when the "isExternalRef" value changes
- getHost().refresh();
- }
- }
-
- protected boolean isExternalRef(View view) {
- return NotationHelper.isExternalRef(view);
- }
-
- /**
- * Returns the marker instance. It is never null
- *
- * @return
- */
- protected IPapyrusMarker getMarker() {
- if (marker == null) {
- marker = new ExternalReferenceMarker(getView());
- }
- return marker;
- }
-
- /**
- * Return the view associated to this edit policy
- *
- * @return
- */
- protected View getView() {
- return (View) getHost().getModel();
- }
-
- @Override
- public void deactivate() {
- super.deactivate();
-
- if (marker != null && decorationService != null) {
- // Remove the marker from the View to avoid duplication
- decorationService.removeDecoration(getMarker().toString());
- isExternalReference = false;
- }
-
- marker = null;
- decorationService = null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.emf.common.notify.Adapter;
+import org.eclipse.gmf.runtime.gef.ui.internal.editpolicies.GraphicalEditPolicyEx;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.decoration.ExternalReferenceMarker;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+import org.eclipse.papyrus.infra.services.decoration.DecorationService;
+import org.eclipse.papyrus.infra.services.markerlistener.IPapyrusMarker;
+
+/**
+ * A generic EditPolicy which applies {@link ExternalReferenceMarker} to EditParts when they have been imported
+ * (According to {@link NotationHelper#isExternalRef(View)}
+ *
+ * @author Camille Letavernier
+ *
+ */
+// Rely on the GraphicalEditPolicyEx, which is less expensive than adding a listener to detect changes in the containment tree
+@SuppressWarnings("restriction")
+public class ExternalReferenceEditPolicy extends GraphicalEditPolicyEx {
+
+ /**
+ * The Edit Policy Role/ID
+ */
+ public static final Object EDIT_POLICY_ROLE = Activator.ID + ".externalReferenceDecorator"; //$NON-NLS-1$
+
+ /**
+ * Last known value for isExternalReference
+ */
+ protected boolean isExternalReference = false;
+
+ protected DecorationService decorationService;
+
+ protected IPapyrusMarker marker;
+
+ protected Adapter listener;
+
+ @Override
+ public void activate() {
+ super.activate();
+
+ try {
+ decorationService = ServiceUtilsForEditPart.getInstance().getService(DecorationService.class, getHost());
+ refresh();
+ } catch (ServiceException ex) {
+ // Ignored; do nothing
+ }
+ }
+
+ @Override
+ public void refresh() {
+ if (getView() == null) {
+ return;
+ }
+ if (decorationService == null) {
+ return;
+ }
+
+ // Add or remove the decoration when the current value is different from the last known value
+ if (isExternalRef(getView()) != isExternalReference) {
+ isExternalReference = !isExternalReference;
+ if (isExternalReference) {
+ decorationService.addDecoration(getMarker(), getView());
+ } else {
+ decorationService.removeDecoration(getMarker().toString());
+ }
+ // We need to call refresh again, so that the decorator gets display.
+ // We shouldn't end up with a StackOverFlow, because we arrive here only when the "isExternalRef" value changes
+ getHost().refresh();
+ }
+ }
+
+ protected boolean isExternalRef(View view) {
+ return NotationHelper.isExternalRef(view);
+ }
+
+ /**
+ * Returns the marker instance. It is never null
+ *
+ * @return
+ */
+ protected IPapyrusMarker getMarker() {
+ if (marker == null) {
+ marker = new ExternalReferenceMarker(getView());
+ }
+ return marker;
+ }
+
+ /**
+ * Return the view associated to this edit policy
+ *
+ * @return
+ */
+ protected View getView() {
+ return (View) getHost().getModel();
+ }
+
+ @Override
+ public void deactivate() {
+ super.deactivate();
+
+ if (marker != null && decorationService != null) {
+ // Remove the marker from the View to avoid duplication
+ decorationService.removeDecoration(getMarker().toString());
+ isExternalReference = false;
+ }
+
+ marker = null;
+ decorationService = null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/FollowSVGSymbolEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/FollowSVGSymbolEditPolicy.java
index b5993f52626..d70f8854345 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/FollowSVGSymbolEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/FollowSVGSymbolEditPolicy.java
@@ -1,86 +1,86 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.core.databinding.observable.ChangeEvent;
-import org.eclipse.core.databinding.observable.IChangeListener;
-import org.eclipse.core.databinding.observable.value.IObservableValue;
-import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomBooleanStyleObservableValue;
-
-/**
- * this edit policy has in charge to display follow the symbol associated to the node
- * associated figure has to be a {@link NodeNamedElementFigure}
- */
-public class FollowSVGSymbolEditPolicy extends GraphicalEditPolicy implements IChangeListener {
-
- /**
- * name of the style to get for follow the Symbol
- */
- public static final String FOLLOW_SVG_SYMBOL = "followSVGSymbol";
-
- /** key for this edit policy */
- public final static String FOLLOW_SVG_SYMBOL_EDITPOLICY = "followSVGSymbolEditPolicy";
-
- protected IObservableValue styleObservable;
-
- /**
- * Creates a new QualifiedNameDisplayEditPolicy
- */
- public FollowSVGSymbolEditPolicy() {
- super();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void activate() {
- // retrieve the view and the element managed by the edit part
- View view = (View) getHost().getModel();
- if (view == null) {
- return;
- }
-
- styleObservable = new CustomBooleanStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), FOLLOW_SVG_SYMBOL);
- styleObservable.addChangeListener(this);
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void deactivate() {
- // retrieve the view and the element managed by the edit part
- View view = (View) getHost().getModel();
- if (view == null) {
- return;
- }
- if (styleObservable != null) {
- styleObservable.removeChangeListener(this);
- styleObservable.dispose();
- styleObservable = null;
- }
- }
-
- @Override
- public void handleChange(ChangeEvent event) {
- getHost().refresh();
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.core.databinding.observable.ChangeEvent;
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.databinding.custom.CustomBooleanStyleObservableValue;
+
+/**
+ * this edit policy has in charge to display follow the symbol associated to the node
+ * associated figure has to be a {@link NodeNamedElementFigure}
+ */
+public class FollowSVGSymbolEditPolicy extends GraphicalEditPolicy implements IChangeListener {
+
+ /**
+ * name of the style to get for follow the Symbol
+ */
+ public static final String FOLLOW_SVG_SYMBOL = "followSVGSymbol";
+
+ /** key for this edit policy */
+ public final static String FOLLOW_SVG_SYMBOL_EDITPOLICY = "followSVGSymbolEditPolicy";
+
+ protected IObservableValue styleObservable;
+
+ /**
+ * Creates a new QualifiedNameDisplayEditPolicy
+ */
+ public FollowSVGSymbolEditPolicy() {
+ super();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void activate() {
+ // retrieve the view and the element managed by the edit part
+ View view = (View) getHost().getModel();
+ if (view == null) {
+ return;
+ }
+
+ styleObservable = new CustomBooleanStyleObservableValue(view, EMFHelper.resolveEditingDomain(view), FOLLOW_SVG_SYMBOL);
+ styleObservable.addChangeListener(this);
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void deactivate() {
+ // retrieve the view and the element managed by the edit part
+ View view = (View) getHost().getModel();
+ if (view == null) {
+ return;
+ }
+ if (styleObservable != null) {
+ styleObservable.removeChangeListener(this);
+ styleObservable.dispose();
+ styleObservable = null;
+ }
+ }
+
+ @Override
+ public void handleChange(ChangeEvent event) {
+ getHost().refresh();
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/GetChildLayoutEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/GetChildLayoutEditPolicy.java
index 0509bf27748..dfc68381e3b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/GetChildLayoutEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/GetChildLayoutEditPolicy.java
@@ -1,68 +1,68 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST 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:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.editpolicies.LayoutEditPolicy;
-import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
-import org.eclipse.gef.requests.CreateRequest;
-
-/**
- * This edit policy replaces the GMF generated edit policy for External Label.
- * In particular it installs {@link ExternalLabelPrimaryDragRoleEditPolicy} on
- * children that are external label.
- */
-public class GetChildLayoutEditPolicy extends LayoutEditPolicy {
-
- /**
- * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
- *
- * @param child
- * @return
- */
- @Override
- protected EditPolicy createChildEditPolicy(EditPart child) {
- // View childView = (View)child.getModel();
- EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
- if(result == null) {
- result = new NonResizableEditPolicy();
- }
- return result;
- }
-
- /**
- * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getMoveChildrenCommand(org.eclipse.gef.Request)
- *
- * @param request
- * @return
- */
- @Override
- protected Command getMoveChildrenCommand(Request request) {
- return null;
- }
-
- /**
- * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
- *
- * @param request
- * @return
- */
- @Override
- protected Command getCreateCommand(CreateRequest request) {
- return null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editpolicies.LayoutEditPolicy;
+import org.eclipse.gef.editpolicies.NonResizableEditPolicy;
+import org.eclipse.gef.requests.CreateRequest;
+
+/**
+ * This edit policy replaces the GMF generated edit policy for External Label.
+ * In particular it installs {@link ExternalLabelPrimaryDragRoleEditPolicy} on
+ * children that are external label.
+ */
+public class GetChildLayoutEditPolicy extends LayoutEditPolicy {
+
+ /**
+ * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#createChildEditPolicy(org.eclipse.gef.EditPart)
+ *
+ * @param child
+ * @return
+ */
+ @Override
+ protected EditPolicy createChildEditPolicy(EditPart child) {
+ // View childView = (View)child.getModel();
+ EditPolicy result = child.getEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE);
+ if(result == null) {
+ result = new NonResizableEditPolicy();
+ }
+ return result;
+ }
+
+ /**
+ * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getMoveChildrenCommand(org.eclipse.gef.Request)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected Command getMoveChildrenCommand(Request request) {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
+ *
+ * @param request
+ * @return
+ */
+ @Override
+ protected Command getCreateCommand(CreateRequest request) {
+ return null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/HighlightEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/HighlightEditPolicy.java
index 02fc1dd7549..5ee999df746 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/HighlightEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/HighlightEditPolicy.java
@@ -1,75 +1,75 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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:
- * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.HighlightUtil;
-
-/**
- * EditPolicy dedicated to highligh node/edge in case of mouseover.
- *
- * @author flefevre
- *
- */
-public class HighlightEditPolicy extends GraphicalEditPolicy {
-
- public static final String HIGHLIGHT_ROLE = "Highlight Edit Policy";
-
-
- @Override
- public void showTargetFeedback(Request request) {
- EditPart host = getHost();
-
- if (RequestConstants.REQ_DROP_OBJECTS.equals(request.getType())) {
- highlight(host);
- }
- }
-
- /**
- * Highlight, subclass can override it.
- */
- protected void highlight(EditPart object) {
- HighlightUtil.highlight(object);
- }
-
- /**
- * Erase highlighted figure, subclass can override it.
- */
- protected void unhighlight(EditPart object) {
- HighlightUtil.unhighlight(object);
- }
-
- /**
- * Erase all highlighted figures, subclass can override it.
- */
- protected void unhighlight() {
- HighlightUtil.unhighlight();
- }
-
-
-
- @Override
- public void eraseTargetFeedback(Request request) {
- unhighlight();
- }
-
- @Override
- public void eraseSourceFeedback(Request request) {
- super.eraseSourceFeedback(request);
-
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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:
+ * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.HighlightUtil;
+
+/**
+ * EditPolicy dedicated to highligh node/edge in case of mouseover.
+ *
+ * @author flefevre
+ *
+ */
+public class HighlightEditPolicy extends GraphicalEditPolicy {
+
+ public static final String HIGHLIGHT_ROLE = "Highlight Edit Policy";
+
+
+ @Override
+ public void showTargetFeedback(Request request) {
+ EditPart host = getHost();
+
+ if (RequestConstants.REQ_DROP_OBJECTS.equals(request.getType())) {
+ highlight(host);
+ }
+ }
+
+ /**
+ * Highlight, subclass can override it.
+ */
+ protected void highlight(EditPart object) {
+ HighlightUtil.highlight(object);
+ }
+
+ /**
+ * Erase highlighted figure, subclass can override it.
+ */
+ protected void unhighlight(EditPart object) {
+ HighlightUtil.unhighlight(object);
+ }
+
+ /**
+ * Erase all highlighted figures, subclass can override it.
+ */
+ protected void unhighlight() {
+ HighlightUtil.unhighlight();
+ }
+
+
+
+ @Override
+ public void eraseTargetFeedback(Request request) {
+ unhighlight();
+ }
+
+ @Override
+ public void eraseSourceFeedback(Request request) {
+ super.eraseSourceFeedback(request);
+
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/IDiagramInformationProviderEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/IDiagramInformationProviderEditPolicy.java
index a2be732de04..8ac0c0147d0 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/IDiagramInformationProviderEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/IDiagramInformationProviderEditPolicy.java
@@ -1,40 +1,40 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure;
-import org.eclipse.papyrus.infra.gmfdiag.common.updater.DiagramUpdater;
-
-/**
- *
- * The EditPolicy used to get informations about the diagram
- *
- */
-public interface IDiagramInformationProviderEditPolicy {
-
-
- /**
- *
- * @return
- * the diagram updater
- */
- public DiagramUpdater getDiagramUpdater();
-
- /**
- *
- * @return
- * the diagram structure
- */
- public DiagramStructure getDiagramStructure();
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.papyrus.infra.gmfdiag.common.structure.DiagramStructure;
+import org.eclipse.papyrus.infra.gmfdiag.common.updater.DiagramUpdater;
+
+/**
+ *
+ * The EditPolicy used to get informations about the diagram
+ *
+ */
+public interface IDiagramInformationProviderEditPolicy {
+
+
+ /**
+ *
+ * @return
+ * the diagram updater
+ */
+ public DiagramUpdater getDiagramUpdater();
+
+ /**
+ *
+ * @return
+ * the diagram structure
+ */
+ public DiagramStructure getDiagramStructure();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java
index 481aa72e222..c77f54bb8a5 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/LabelAlignmentEditPolicy.java
@@ -1,204 +1,204 @@
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gef.editpolicies.AbstractEditPolicy;
-import org.eclipse.gef.requests.AlignmentRequest;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-
-/**
- * This EditPolicy provides the command for the alignment. In the case of
- * Label.
- */
-public class LabelAlignmentEditPolicy extends AbstractEditPolicy{
-
- /**
- * the key for the Port Alignment EditPolicy
- */
- public static final String LABEL_ALIGNMENT_KEY = "Label Alignment"; //$NON-NLS-1$
-
-
- /** Integer corresponding to the alignment type ( p.e. Left = 1, Bottom = 32) */
- private int alignment ;
-
- /** Current edit Part */
- private GraphicalEditPart label ;
-
- /** Reference rectangle on which the Label is aligned */
- private Rectangle refBounds;
-
- /** Bounds of the current label */
- private Rectangle bounds;
-
- /**
- * Get Command associate to the corresponding Request
- * Only REQ_ALIGN request return a Command
- * @return Command to move the label in case of REQ_ALIGN, null if not.
- * @param request Request for which a command is required.
- */
- public Command getCommand(Request request) {
- Command cmd = null;
- if (REQ_ALIGN.equals(request.getType())){
- cmd = getAlignLabelCommand ((AlignmentRequest) request);
- }
- return cmd;
- }
-
- /**
- * Get The alignment Command for the corresponding Alignment Request.
- * This method transforms the alignment Request into a move request and return the move command associated to this new Request.
- *
- * @param request Alignment Request for which the Alignment Command is returned
- * @return Alignment command
- */
- private Command getAlignLabelCommand(AlignmentRequest request) {
-
- alignment = request.getAlignment();
- // get the Alignment rectangle on which the selected edit part should be aligned.
- refBounds = request.getAlignmentRectangle().getCopy();
-
- label = (GraphicalEditPart) getHost();
- bounds = getAbsolutePosition(label);
-
- Point moveDelta = new Point(0, 0);
-
- if (isAlignmentAllowed()){
- switch (alignment ){
- case PositionConstants.LEFT:
- moveDelta.setX(refBounds.x - bounds.x );
- break;
- case PositionConstants.RIGHT:
- moveDelta.setX(refBounds.getRight().x - bounds.getRight().x );
- break;
- case PositionConstants.TOP:
- moveDelta.setY(refBounds.y - bounds.y );
- break;
- case PositionConstants.BOTTOM:
- moveDelta.setY(refBounds.getBottom().y - bounds.getBottom().y );
- break;
- case PositionConstants.CENTER:
- moveDelta.setX(refBounds.getTop().x - bounds.getTop().x );
- break;
- case PositionConstants.MIDDLE:
- moveDelta.setY(refBounds.getLeft().y - bounds.getLeft().y );
- break;
- }
-
-
- //build the Move request
- ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE);
-
- req.setEditParts(((ChangeBoundsRequest)request).getEditParts());
- req.setMoveDelta(moveDelta);
- req.setExtendedData(request.getExtendedData());
-
- return getHost().getCommand(req);
-
- }
- else {
- // if alignment not allowed return no command
- return null;
-
- }
-
- }
-
- /**
- * Determine if the current edit part can be aligned.
- *
- * The label cannot be aligned if its connector target or source moves as well
- * Because if the source/target moves, the connector moves as well and the label linked to the connector translates with the Edge
- * Same if the Affixed node is selected.
- */
- private boolean isAlignmentAllowed() {
- EditPart parent = label.getParent();
- boolean isAllow = true;
- if (parent instanceof AbstractConnectionEditPart){
- // Label alignment is not allowed if it should moves at the same time as the connector
- // That means if the Source or target of the connector is part of the selection
- int sourceSelectionType = ((ConnectionEditPart)label.getParent()).getSource().getSelected();
- int targetSelectionType = ((ConnectionEditPart)label.getParent()).getTarget().getSelected();
-
-
- boolean isRefDependent = isRefSibling(parent);
-
- if (!isRefDependent) {
- boolean isExtremitiesSelected = (sourceSelectionType == EditPart.SELECTED)||(targetSelectionType == EditPart.SELECTED);
- isAllow = !isExtremitiesSelected;
- }
-
-
- } else if (parent instanceof AbstractBorderItemEditPart) {
- // if the label is an affixed label and if the affixed node is part of the selection, the label is not aligned
- isAllow = !(parent.getSelected() == EditPart.SELECTED);
- }
-
- return isAllow;
- }
-
- /**
- * Define if the Label is sibling of the Reference object.
- * @param parent Label's Parent
- * @return true if the reference is a sibling of the Label
- */
- private boolean isRefSibling(EditPart parent) {
-
- boolean isRefSibling = false;
- if (parent instanceof AbstractConnectionEditPart){
-
- List<?> children = parent.getChildren();
- Iterator<?> iter = children.iterator();
-
- while(iter.hasNext() && !isRefSibling ){
- Object child = iter.next();
- if (((EditPart)child).getSelected() == EditPart.SELECTED_PRIMARY){
- isRefSibling = true;
- }
- }
- }
- return isRefSibling;
- }
-
- /**
- *
- * A {@link Rectangle} with the absolute position from the {@link EditPart}
- *
- * @param ep
- * the {@link EditPart} that we want the position
- * @return a {@link Rectangle} with the absolute position from the {@link EditPart}
- *
- */
- public static Rectangle getAbsolutePosition(EditPart ep) {
- GraphicalEditPart part = (GraphicalEditPart)ep;
- Rectangle rect = part.getFigure().getBounds().getCopy();
- part.getFigure().translateToAbsolute(rect);
- return rect;
- }
-
-
-
-}
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+import org.eclipse.gef.requests.AlignmentRequest;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+
+/**
+ * This EditPolicy provides the command for the alignment. In the case of
+ * Label.
+ */
+public class LabelAlignmentEditPolicy extends AbstractEditPolicy{
+
+ /**
+ * the key for the Port Alignment EditPolicy
+ */
+ public static final String LABEL_ALIGNMENT_KEY = "Label Alignment"; //$NON-NLS-1$
+
+
+ /** Integer corresponding to the alignment type ( p.e. Left = 1, Bottom = 32) */
+ private int alignment ;
+
+ /** Current edit Part */
+ private GraphicalEditPart label ;
+
+ /** Reference rectangle on which the Label is aligned */
+ private Rectangle refBounds;
+
+ /** Bounds of the current label */
+ private Rectangle bounds;
+
+ /**
+ * Get Command associate to the corresponding Request
+ * Only REQ_ALIGN request return a Command
+ * @return Command to move the label in case of REQ_ALIGN, null if not.
+ * @param request Request for which a command is required.
+ */
+ public Command getCommand(Request request) {
+ Command cmd = null;
+ if (REQ_ALIGN.equals(request.getType())){
+ cmd = getAlignLabelCommand ((AlignmentRequest) request);
+ }
+ return cmd;
+ }
+
+ /**
+ * Get The alignment Command for the corresponding Alignment Request.
+ * This method transforms the alignment Request into a move request and return the move command associated to this new Request.
+ *
+ * @param request Alignment Request for which the Alignment Command is returned
+ * @return Alignment command
+ */
+ private Command getAlignLabelCommand(AlignmentRequest request) {
+
+ alignment = request.getAlignment();
+ // get the Alignment rectangle on which the selected edit part should be aligned.
+ refBounds = request.getAlignmentRectangle().getCopy();
+
+ label = (GraphicalEditPart) getHost();
+ bounds = getAbsolutePosition(label);
+
+ Point moveDelta = new Point(0, 0);
+
+ if (isAlignmentAllowed()){
+ switch (alignment ){
+ case PositionConstants.LEFT:
+ moveDelta.setX(refBounds.x - bounds.x );
+ break;
+ case PositionConstants.RIGHT:
+ moveDelta.setX(refBounds.getRight().x - bounds.getRight().x );
+ break;
+ case PositionConstants.TOP:
+ moveDelta.setY(refBounds.y - bounds.y );
+ break;
+ case PositionConstants.BOTTOM:
+ moveDelta.setY(refBounds.getBottom().y - bounds.getBottom().y );
+ break;
+ case PositionConstants.CENTER:
+ moveDelta.setX(refBounds.getTop().x - bounds.getTop().x );
+ break;
+ case PositionConstants.MIDDLE:
+ moveDelta.setY(refBounds.getLeft().y - bounds.getLeft().y );
+ break;
+ }
+
+
+ //build the Move request
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE);
+
+ req.setEditParts(((ChangeBoundsRequest)request).getEditParts());
+ req.setMoveDelta(moveDelta);
+ req.setExtendedData(request.getExtendedData());
+
+ return getHost().getCommand(req);
+
+ }
+ else {
+ // if alignment not allowed return no command
+ return null;
+
+ }
+
+ }
+
+ /**
+ * Determine if the current edit part can be aligned.
+ *
+ * The label cannot be aligned if its connector target or source moves as well
+ * Because if the source/target moves, the connector moves as well and the label linked to the connector translates with the Edge
+ * Same if the Affixed node is selected.
+ */
+ private boolean isAlignmentAllowed() {
+ EditPart parent = label.getParent();
+ boolean isAllow = true;
+ if (parent instanceof AbstractConnectionEditPart){
+ // Label alignment is not allowed if it should moves at the same time as the connector
+ // That means if the Source or target of the connector is part of the selection
+ int sourceSelectionType = ((ConnectionEditPart)label.getParent()).getSource().getSelected();
+ int targetSelectionType = ((ConnectionEditPart)label.getParent()).getTarget().getSelected();
+
+
+ boolean isRefDependent = isRefSibling(parent);
+
+ if (!isRefDependent) {
+ boolean isExtremitiesSelected = (sourceSelectionType == EditPart.SELECTED)||(targetSelectionType == EditPart.SELECTED);
+ isAllow = !isExtremitiesSelected;
+ }
+
+
+ } else if (parent instanceof AbstractBorderItemEditPart) {
+ // if the label is an affixed label and if the affixed node is part of the selection, the label is not aligned
+ isAllow = !(parent.getSelected() == EditPart.SELECTED);
+ }
+
+ return isAllow;
+ }
+
+ /**
+ * Define if the Label is sibling of the Reference object.
+ * @param parent Label's Parent
+ * @return true if the reference is a sibling of the Label
+ */
+ private boolean isRefSibling(EditPart parent) {
+
+ boolean isRefSibling = false;
+ if (parent instanceof AbstractConnectionEditPart){
+
+ List<?> children = parent.getChildren();
+ Iterator<?> iter = children.iterator();
+
+ while(iter.hasNext() && !isRefSibling ){
+ Object child = iter.next();
+ if (((EditPart)child).getSelected() == EditPart.SELECTED_PRIMARY){
+ isRefSibling = true;
+ }
+ }
+ }
+ return isRefSibling;
+ }
+
+ /**
+ *
+ * A {@link Rectangle} with the absolute position from the {@link EditPart}
+ *
+ * @param ep
+ * the {@link EditPart} that we want the position
+ * @return a {@link Rectangle} with the absolute position from the {@link EditPart}
+ *
+ */
+ public static Rectangle getAbsolutePosition(EditPart ep) {
+ GraphicalEditPart part = (GraphicalEditPart)ep;
+ Rectangle rect = part.getFigure().getBounds().getCopy();
+ part.getFigure().translateToAbsolute(rect);
+ return rect;
+ }
+
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/NoSemanticParserEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/NoSemanticParserEditPolicy.java
index e64b2e6aa03..ae359e3b4fc 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/NoSemanticParserEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/NoSemanticParserEditPolicy.java
@@ -1,53 +1,53 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.eclipse.gef.editpolicies.AbstractEditPolicy;
-
-/**
- * Do nothing
- */
-public class NoSemanticParserEditPolicy extends AbstractEditPolicy implements IMaskManagedLabelEditPolicy {
-
- @Override
- public Map<String, String> getMasks() {
- // Nothing
- return null;
- }
-
- @Override
- public Collection<String> getCurrentDisplayValue() {
- // Nothing
- return null;
- }
-
- @Override
- public void refreshDisplay() {
- // Nothing
- }
-
- @Override
- public void updateDisplayValue(Collection<String> newValue) {
- // Nothing
- }
-
- @Override
- public void setDefaultDisplayValue() {
- // Nothing
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import java.util.Collection;
+import java.util.Map;
+
+import org.eclipse.gef.editpolicies.AbstractEditPolicy;
+
+/**
+ * Do nothing
+ */
+public class NoSemanticParserEditPolicy extends AbstractEditPolicy implements IMaskManagedLabelEditPolicy {
+
+ @Override
+ public Map<String, String> getMasks() {
+ // Nothing
+ return null;
+ }
+
+ @Override
+ public Collection<String> getCurrentDisplayValue() {
+ // Nothing
+ return null;
+ }
+
+ @Override
+ public void refreshDisplay() {
+ // Nothing
+ }
+
+ @Override
+ public void updateDisplayValue(Collection<String> newValue) {
+ // Nothing
+ }
+
+ @Override
+ public void setDefaultDisplayValue() {
+ // Nothing
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusConnectionEndEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusConnectionEndEditPolicy.java
index 2be5bb672c6..5c8a3ca62db 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusConnectionEndEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusConnectionEndEditPolicy.java
@@ -1,53 +1,53 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.draw2d.ConnectionLocator;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.snap.PapyrusConnectionEndpointHandle;
-
-
-/**
- *
- * This class allows to provides our own EndPointHandle to provide our own DragTracker
- *
- */
-public class PapyrusConnectionEndEditPolicy extends ConnectionEndpointEditPolicy {
-
- /**
- *
- * Constructor.
- *
- */
- public PapyrusConnectionEndEditPolicy() {
- super();
- }
-
- /**
- * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles()
- */
- @Override
- protected List<?> createSelectionHandles() {
- List<PapyrusConnectionEndpointHandle> list = new ArrayList<PapyrusConnectionEndpointHandle>();
- list.add(new PapyrusConnectionEndpointHandle((ConnectionEditPart) getHost(), ConnectionLocator.SOURCE));
- list.add(new PapyrusConnectionEndpointHandle((ConnectionEditPart) getHost(), ConnectionLocator.TARGET));
- return list;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.ConnectionLocator;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.editpolicies.ConnectionEndpointEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.PapyrusConnectionEndpointHandle;
+
+
+/**
+ *
+ * This class allows to provides our own EndPointHandle to provide our own DragTracker
+ *
+ */
+public class PapyrusConnectionEndEditPolicy extends ConnectionEndpointEditPolicy {
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public PapyrusConnectionEndEditPolicy() {
+ super();
+ }
+
+ /**
+ * @see org.eclipse.gef.editpolicies.SelectionHandlesEditPolicy#createSelectionHandles()
+ */
+ @Override
+ protected List<?> createSelectionHandles() {
+ List<PapyrusConnectionEndpointHandle> list = new ArrayList<PapyrusConnectionEndpointHandle>();
+ list.add(new PapyrusConnectionEndpointHandle((ConnectionEditPart) getHost(), ConnectionLocator.SOURCE));
+ list.add(new PapyrusConnectionEndpointHandle((ConnectionEditPart) getHost(), ConnectionLocator.TARGET));
+ return list;
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java
index 86ddc758eb6..77c3b6e855c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/PapyrusResizableShapeEditPolicy.java
@@ -1,213 +1,213 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.tools.ResizeTracker;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableShapeEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.snap.ResizeTrackerWithPreferences;
-
-/**
- *
- * See Bug 424943 ResizableEditPolicy#getResizeCommand duplicates request ignoring some request values
- *
- */
-public class PapyrusResizableShapeEditPolicy extends ResizableShapeEditPolicy {
-
- /**
- * The same {@link ChangeBoundsRequest} is sent to all moved edit parts,
- * so we can cache the info about them in request potentially improving o(N^2) performance.
- */
- private static final String PARAM_CACHED_EDIT_PARTS_SET = PapyrusResizableShapeEditPolicy.class.getName() + ":CachedMovedEPs";
-
- /**
- * Tries to find the cached instance of {@link CachedEditPartsSet} in the request extended data map.
- * If not found, initializes the new instance and caches it in request for other edit-policy instances.
- *
- * @param req
- * @return never returns <code>null</code>
- */
- @SuppressWarnings({ "rawtypes", "unchecked" })
- protected static CachedEditPartsSet getMovedEditPartsSet(ChangeBoundsRequest req) {
- Map extData = req.getExtendedData();
- CachedEditPartsSet set = (CachedEditPartsSet) extData.get(PARAM_CACHED_EDIT_PARTS_SET);
- if (set == null) {
- set = new CachedEditPartsSet(req.getEditParts());
- extData.put(PARAM_CACHED_EDIT_PARTS_SET, set);
- }
- return set;
- }
-
- /**
- * This implementation overrides {@link org.eclipse.gef.editpolicies.NonResizableEditPolicy#getMoveCommand} and keeps all parent's logic.
- * Multi-selection request identified by the presence of {@link PapyrusResizableShapeEditPolicy#PARAM_CACHED_EDIT_PARTS_SET} key
- * for request extended data
- * see {@link org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.XYLayoutWithConstrainedResizedEditPolicy#getConnectionsToElementsNotBeingMoved}
- *
- * @param request
- * the change bounds request
- * @return the command contribution to the request
- */
- @SuppressWarnings("unchecked")
- @Override
- protected Command getMoveCommand(ChangeBoundsRequest request) {
- ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
- req.setEditParts(getHost());
- req.setMoveDelta(request.getMoveDelta());
- req.setSizeDelta(request.getSizeDelta());
- req.setLocation(request.getLocation());
- Map<Object, Object> extendedData = new HashMap<Object, Object>();
- extendedData.putAll(request.getExtendedData());
- CachedEditPartsSet set = new CachedEditPartsSet(request.getEditParts());
- extendedData.put(PARAM_CACHED_EDIT_PARTS_SET, set);
- req.setExtendedData(extendedData);
- return getHost().getParent().getCommand(req);
- }
-
- /**
- * See Bug 424943 ResizableEditPolicy#getResizeCommand duplicates request ignoring some request values
- * TODO : remove this override when the bug will be fixed
- *
- * Returns the command contribution for the given resize request. By
- * default, the request is re-dispatched to the host's parent as a {@link org.eclipse.gef.RequestConstants#REQ_RESIZE_CHILDREN}. The
- * parent's edit policies determine how to perform the resize based on the
- * layout manager in use.
- *
- * @param request
- * the resize request
- * @return the command contribution obtained from the parent
- */
-
- @Override
- protected Command getResizeCommand(ChangeBoundsRequest request) {
- ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_RESIZE_CHILDREN);
- req.setCenteredResize(request.isCenteredResize());
- req.setConstrainedMove(request.isConstrainedMove());
- req.setConstrainedResize(request.isConstrainedResize());
- req.setSnapToEnabled(request.isSnapToEnabled());
- req.setEditParts(getHost());
-
- req.setMoveDelta(request.getMoveDelta());
- req.setSizeDelta(request.getSizeDelta());
- req.setLocation(request.getLocation());
- req.setExtendedData(request.getExtendedData());
- req.setResizeDirection(request.getResizeDirection());
-
- if (getHost().getParent() == null) {
- return null;
- }
-
- return getHost().getParent().getCommand(req);
- }
-
- /**
- *
- * @see org.eclipse.gef.editpolicies.ResizableEditPolicy#getResizeTracker(int)
- *
- * @param direction
- * @return
- */
- @Override
- protected ResizeTracker getResizeTracker(int direction) {
- return new ResizeTrackerWithPreferences((GraphicalEditPart) getHost(), direction);
- }
-
- protected static enum MovedNodeKind {
- DIRECTLY, INDIRECTLY, NO
- }
-
- protected static class CachedEditPartsSet {
-
- private final Set<EditPart> myDirectlyMoved;
-
- private final Set<EditPart> myKnownIndirectlyYes;
-
- private final Set<EditPart> myKnownIndirectlyNo;
-
- public CachedEditPartsSet(List<EditPart> directlyMoved) {
- myDirectlyMoved = new HashSet<EditPart>(directlyMoved);
- myKnownIndirectlyNo = new HashSet<EditPart>(directlyMoved.size() * 5 + 1);
- myKnownIndirectlyYes = new HashSet<EditPart>(directlyMoved.size() * 5 + 1);
- }
-
- public boolean isMovedEditPart(EditPart ep) {
- return isMoved(ep) != MovedNodeKind.NO;
- }
-
- public MovedNodeKind isMoved(EditPart ep) {
- List<EditPart> chainUp = new LinkedList<EditPart>();
- EditPart cur = ep;
- MovedNodeKind kind = null;
- while (cur != null) {
- kind = getKnownKind(cur);
- if (kind != null) {
- break;
- }
- chainUp.add(cur);
- cur = cur.getParent();
- }
- if (cur == null || kind == null) {
- kind = MovedNodeKind.NO;
- } else if (kind == MovedNodeKind.DIRECTLY && cur != ep) {
- kind = MovedNodeKind.INDIRECTLY;
- }
-
- Set<EditPart> forKind;
- switch (kind) {
- case DIRECTLY:
- forKind = myDirectlyMoved;
- break;
- case INDIRECTLY:
- forKind = myKnownIndirectlyYes;
- break;
- case NO:
- forKind = myKnownIndirectlyNo;
- break;
- default:
- throw new IllegalArgumentException("Wow: " + kind);
- }
-
- if (kind != MovedNodeKind.DIRECTLY) {
- forKind.addAll(chainUp);
- }
-
- return kind;
- }
-
- private MovedNodeKind getKnownKind(EditPart ep) {
- if (myDirectlyMoved.contains(ep)) {
- return MovedNodeKind.DIRECTLY;
- }
- if (myKnownIndirectlyYes.contains(ep)) {
- return MovedNodeKind.INDIRECTLY;
- }
- if (myKnownIndirectlyNo.contains(ep)) {
- return MovedNodeKind.NO;
- }
- return null;
- }
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.tools.ResizeTracker;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.ResizableShapeEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.ResizeTrackerWithPreferences;
+
+/**
+ *
+ * See Bug 424943 ResizableEditPolicy#getResizeCommand duplicates request ignoring some request values
+ *
+ */
+public class PapyrusResizableShapeEditPolicy extends ResizableShapeEditPolicy {
+
+ /**
+ * The same {@link ChangeBoundsRequest} is sent to all moved edit parts,
+ * so we can cache the info about them in request potentially improving o(N^2) performance.
+ */
+ private static final String PARAM_CACHED_EDIT_PARTS_SET = PapyrusResizableShapeEditPolicy.class.getName() + ":CachedMovedEPs";
+
+ /**
+ * Tries to find the cached instance of {@link CachedEditPartsSet} in the request extended data map.
+ * If not found, initializes the new instance and caches it in request for other edit-policy instances.
+ *
+ * @param req
+ * @return never returns <code>null</code>
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ protected static CachedEditPartsSet getMovedEditPartsSet(ChangeBoundsRequest req) {
+ Map extData = req.getExtendedData();
+ CachedEditPartsSet set = (CachedEditPartsSet) extData.get(PARAM_CACHED_EDIT_PARTS_SET);
+ if (set == null) {
+ set = new CachedEditPartsSet(req.getEditParts());
+ extData.put(PARAM_CACHED_EDIT_PARTS_SET, set);
+ }
+ return set;
+ }
+
+ /**
+ * This implementation overrides {@link org.eclipse.gef.editpolicies.NonResizableEditPolicy#getMoveCommand} and keeps all parent's logic.
+ * Multi-selection request identified by the presence of {@link PapyrusResizableShapeEditPolicy#PARAM_CACHED_EDIT_PARTS_SET} key
+ * for request extended data
+ * see {@link org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.XYLayoutWithConstrainedResizedEditPolicy#getConnectionsToElementsNotBeingMoved}
+ *
+ * @param request
+ * the change bounds request
+ * @return the command contribution to the request
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ protected Command getMoveCommand(ChangeBoundsRequest request) {
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_MOVE_CHILDREN);
+ req.setEditParts(getHost());
+ req.setMoveDelta(request.getMoveDelta());
+ req.setSizeDelta(request.getSizeDelta());
+ req.setLocation(request.getLocation());
+ Map<Object, Object> extendedData = new HashMap<Object, Object>();
+ extendedData.putAll(request.getExtendedData());
+ CachedEditPartsSet set = new CachedEditPartsSet(request.getEditParts());
+ extendedData.put(PARAM_CACHED_EDIT_PARTS_SET, set);
+ req.setExtendedData(extendedData);
+ return getHost().getParent().getCommand(req);
+ }
+
+ /**
+ * See Bug 424943 ResizableEditPolicy#getResizeCommand duplicates request ignoring some request values
+ * TODO : remove this override when the bug will be fixed
+ *
+ * Returns the command contribution for the given resize request. By
+ * default, the request is re-dispatched to the host's parent as a {@link org.eclipse.gef.RequestConstants#REQ_RESIZE_CHILDREN}. The
+ * parent's edit policies determine how to perform the resize based on the
+ * layout manager in use.
+ *
+ * @param request
+ * the resize request
+ * @return the command contribution obtained from the parent
+ */
+
+ @Override
+ protected Command getResizeCommand(ChangeBoundsRequest request) {
+ ChangeBoundsRequest req = new ChangeBoundsRequest(REQ_RESIZE_CHILDREN);
+ req.setCenteredResize(request.isCenteredResize());
+ req.setConstrainedMove(request.isConstrainedMove());
+ req.setConstrainedResize(request.isConstrainedResize());
+ req.setSnapToEnabled(request.isSnapToEnabled());
+ req.setEditParts(getHost());
+
+ req.setMoveDelta(request.getMoveDelta());
+ req.setSizeDelta(request.getSizeDelta());
+ req.setLocation(request.getLocation());
+ req.setExtendedData(request.getExtendedData());
+ req.setResizeDirection(request.getResizeDirection());
+
+ if (getHost().getParent() == null) {
+ return null;
+ }
+
+ return getHost().getParent().getCommand(req);
+ }
+
+ /**
+ *
+ * @see org.eclipse.gef.editpolicies.ResizableEditPolicy#getResizeTracker(int)
+ *
+ * @param direction
+ * @return
+ */
+ @Override
+ protected ResizeTracker getResizeTracker(int direction) {
+ return new ResizeTrackerWithPreferences((GraphicalEditPart) getHost(), direction);
+ }
+
+ protected static enum MovedNodeKind {
+ DIRECTLY, INDIRECTLY, NO
+ }
+
+ protected static class CachedEditPartsSet {
+
+ private final Set<EditPart> myDirectlyMoved;
+
+ private final Set<EditPart> myKnownIndirectlyYes;
+
+ private final Set<EditPart> myKnownIndirectlyNo;
+
+ public CachedEditPartsSet(List<EditPart> directlyMoved) {
+ myDirectlyMoved = new HashSet<EditPart>(directlyMoved);
+ myKnownIndirectlyNo = new HashSet<EditPart>(directlyMoved.size() * 5 + 1);
+ myKnownIndirectlyYes = new HashSet<EditPart>(directlyMoved.size() * 5 + 1);
+ }
+
+ public boolean isMovedEditPart(EditPart ep) {
+ return isMoved(ep) != MovedNodeKind.NO;
+ }
+
+ public MovedNodeKind isMoved(EditPart ep) {
+ List<EditPart> chainUp = new LinkedList<EditPart>();
+ EditPart cur = ep;
+ MovedNodeKind kind = null;
+ while (cur != null) {
+ kind = getKnownKind(cur);
+ if (kind != null) {
+ break;
+ }
+ chainUp.add(cur);
+ cur = cur.getParent();
+ }
+ if (cur == null || kind == null) {
+ kind = MovedNodeKind.NO;
+ } else if (kind == MovedNodeKind.DIRECTLY && cur != ep) {
+ kind = MovedNodeKind.INDIRECTLY;
+ }
+
+ Set<EditPart> forKind;
+ switch (kind) {
+ case DIRECTLY:
+ forKind = myDirectlyMoved;
+ break;
+ case INDIRECTLY:
+ forKind = myKnownIndirectlyYes;
+ break;
+ case NO:
+ forKind = myKnownIndirectlyNo;
+ break;
+ default:
+ throw new IllegalArgumentException("Wow: " + kind);
+ }
+
+ if (kind != MovedNodeKind.DIRECTLY) {
+ forKind.addAll(chainUp);
+ }
+
+ return kind;
+ }
+
+ private MovedNodeKind getKnownKind(EditPart ep) {
+ if (myDirectlyMoved.contains(ep)) {
+ return MovedNodeKind.DIRECTLY;
+ }
+ if (myKnownIndirectlyYes.contains(ep)) {
+ return MovedNodeKind.INDIRECTLY;
+ }
+ if (myKnownIndirectlyNo.contains(ep)) {
+ return MovedNodeKind.NO;
+ }
+ return null;
+ }
+
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java
index a7a538c0b1b..c02146228d2 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/ShapeCompartmentEditPolicy.java
@@ -1,217 +1,217 @@
-/*****************************************************************************
- * Copyright (c) 2012, 2016 CEA LIST, Christian W. Damus, 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 323802
- * Christian W. Damus - bug 492482
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
-import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
-import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateShapeCompartmentViewCommand;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.NotificationManager;
-import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * this edit policy can be apply only on {@link IPapyrusEditPart} in order to
- * access to primary figure. the primary figure has to be a {@link IPapyrusNodeUMLElementFigure}.
- * This edit policy manage the display of a shape in a new compartment and toggles the compartment display.
- */
-public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements AutomaticNotationEditPolicy, NotificationListener, IPapyrusListener {
-
- /** constant for this edit policy role */
- public final static String SHAPE_COMPARTMENT_EDIT_POLICY = "ShapeCompartmentEditPolicy"; //$NON-NLS-1$
-
- /** manager for notifications: should the compartment react to the notification? */
- protected NotificationManager notificationManager;
-
- /**
- * Creates a new AppliedStereotype display edit policy
- */
- public ShapeCompartmentEditPolicy() {
- super();
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void activate() {
- super.activate();
- // retrieve the view and the element managed by the edit part
- View view = getView();
- if (view == null) {
- return;
- }
- notificationManager = ShapeService.getInstance().createNotificationManager(getDiagramEventBroker(), view, this);
- createShapeCompartment();
-
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void deactivate() {
- // retrieve the view and the element managed by the edit part
- View view = getView();
- if (view == null) {
- return;
- }
- notificationManager.dispose();
- notificationManager = null;
- super.deactivate();
- }
-
- /**
- * Returns the view controlled by the host edit part
- *
- * @return the view controlled by the host edit part
- */
- protected View getView() {
- return (View) getHost().getModel();
- }
-
- /**
- * {@inheritDoc}
- */
- public void refreshDisplay() {
- final IGraphicalEditPart editPart = (IGraphicalEditPart) getHost();
- editPart.refresh();
- }
-
- protected boolean hasToDisplayCompartment(EObject view) {
- return ShapeService.getInstance().hasShapeToDisplay(view);
- }
-
- /**
- * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
- *
- * @param editPart
- * the editpart owner of the new compartment
- * @param appliedstereotype
- * the stereotype application
- */
- protected void executeShapeCompartmentCreation(final IGraphicalEditPart editPart) {
- try {
- // boolean isVisible = hasToDisplayCompartment(editPart.getNotationView());
- TransactionalEditingDomain domain = getEditingDomain(editPart);
- CreateShapeCompartmentViewCommand command = new CreateShapeCompartmentViewCommand(domain, "Create Compartment", "Command that creates the compartment displaying shapes", editPart.getNotationView(), /* isVisible */false);
-
- // This should not change the command stack, as this transaction will only manipulate transient views. Create a transaction manually, if needed
- execute(command);
- } catch (Exception e) {
- Activator.log.error(e);
- }
- }
-
- /**
- * Returns the editing domain for the given edit Part
- *
- * @param editPart
- * the edit part from which editing domain is searched
- * @return the editing domain
- */
- protected TransactionalEditingDomain getEditingDomain(IGraphicalEditPart editPart) {
- return editPart.getEditingDomain();
- }
-
- /**
- * Gets the diagram event broker from the editing domain.
- *
- * @return the diagram event broker
- */
- protected DiagramEventBroker getDiagramEventBroker() {
- TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
- if (theEditingDomain != null) {
- return DiagramEventBroker.getInstance(theEditingDomain);
- }
- return null;
- }
-
- /**
- *
- * {@inheritedDoc}
- */
- @Override
- public void notifyChanged(Notification notification) {
- refreshDisplay();
- }
-
- /**
- * this method creates a node for the compartment of stereotype if it does not exist.
- *
- * @param stereotypeApplication
- * the stereotype application
- */
- public void createShapeCompartment() {
- final IGraphicalEditPart editPart = (IGraphicalEditPart) getHost();
- final View node = editPart.getNotationView();
- // Look for the node for the shape compartment
- View shapeCompartment = getShapeCompartmentView(node);
- // it does not exist
- if (shapeCompartment == null) {
- executeShapeCompartmentCreation(editPart);
- }
- }
-
- /**
- * Returns the view corresponding to the shape compartment
- *
- * @param node
- * @return
- */
- private View getShapeCompartmentView(View node) {
- for (Object child : node.getChildren()) {
- if (child instanceof View && IShapeCompartmentEditPart.VIEW_TYPE.equals(((View) child).getType())) {
- return (View) child;
- }
- }
- return null;
- }
-
- /**
- * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
- *
- * @param editPart
- * the editpart owner of the new compartment
- * @param appliedstereotype
- * the stereotype application
- */
- protected void setVisibility(final View view, final boolean isVisible) {
- final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
- Display.getCurrent().asyncExec(new Runnable() {
-
- @Override
- public void run() {
- SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(editPart.getEditingDomain(), view, isVisible);
- // use to avoid to put it in the command stack
- execute(setCommand);
- }
- });
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2016 CEA LIST, Christian W. Damus, 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 323802
+ * Christian W. Damus - bug 492482
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.editpolicies.GraphicalEditPolicy;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.listenerservice.IPapyrusListener;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.CreateShapeCompartmentViewCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.SetNodeVisibilityCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IPapyrusEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.NotificationManager;
+import org.eclipse.papyrus.infra.gmfdiag.common.service.shape.ShapeService;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * this edit policy can be apply only on {@link IPapyrusEditPart} in order to
+ * access to primary figure. the primary figure has to be a {@link IPapyrusNodeUMLElementFigure}.
+ * This edit policy manage the display of a shape in a new compartment and toggles the compartment display.
+ */
+public class ShapeCompartmentEditPolicy extends GraphicalEditPolicy implements AutomaticNotationEditPolicy, NotificationListener, IPapyrusListener {
+
+ /** constant for this edit policy role */
+ public final static String SHAPE_COMPARTMENT_EDIT_POLICY = "ShapeCompartmentEditPolicy"; //$NON-NLS-1$
+
+ /** manager for notifications: should the compartment react to the notification? */
+ protected NotificationManager notificationManager;
+
+ /**
+ * Creates a new AppliedStereotype display edit policy
+ */
+ public ShapeCompartmentEditPolicy() {
+ super();
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void activate() {
+ super.activate();
+ // retrieve the view and the element managed by the edit part
+ View view = getView();
+ if (view == null) {
+ return;
+ }
+ notificationManager = ShapeService.getInstance().createNotificationManager(getDiagramEventBroker(), view, this);
+ createShapeCompartment();
+
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void deactivate() {
+ // retrieve the view and the element managed by the edit part
+ View view = getView();
+ if (view == null) {
+ return;
+ }
+ notificationManager.dispose();
+ notificationManager = null;
+ super.deactivate();
+ }
+
+ /**
+ * Returns the view controlled by the host edit part
+ *
+ * @return the view controlled by the host edit part
+ */
+ protected View getView() {
+ return (View) getHost().getModel();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void refreshDisplay() {
+ final IGraphicalEditPart editPart = (IGraphicalEditPart) getHost();
+ editPart.refresh();
+ }
+
+ protected boolean hasToDisplayCompartment(EObject view) {
+ return ShapeService.getInstance().hasShapeToDisplay(view);
+ }
+
+ /**
+ * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
+ *
+ * @param editPart
+ * the editpart owner of the new compartment
+ * @param appliedstereotype
+ * the stereotype application
+ */
+ protected void executeShapeCompartmentCreation(final IGraphicalEditPart editPart) {
+ try {
+ // boolean isVisible = hasToDisplayCompartment(editPart.getNotationView());
+ TransactionalEditingDomain domain = getEditingDomain(editPart);
+ CreateShapeCompartmentViewCommand command = new CreateShapeCompartmentViewCommand(domain, "Create Compartment", "Command that creates the compartment displaying shapes", editPart.getNotationView(), /* isVisible */false);
+
+ // This should not change the command stack, as this transaction will only manipulate transient views. Create a transaction manually, if needed
+ execute(command);
+ } catch (Exception e) {
+ Activator.log.error(e);
+ }
+ }
+
+ /**
+ * Returns the editing domain for the given edit Part
+ *
+ * @param editPart
+ * the edit part from which editing domain is searched
+ * @return the editing domain
+ */
+ protected TransactionalEditingDomain getEditingDomain(IGraphicalEditPart editPart) {
+ return editPart.getEditingDomain();
+ }
+
+ /**
+ * Gets the diagram event broker from the editing domain.
+ *
+ * @return the diagram event broker
+ */
+ protected DiagramEventBroker getDiagramEventBroker() {
+ TransactionalEditingDomain theEditingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+ if (theEditingDomain != null) {
+ return DiagramEventBroker.getInstance(theEditingDomain);
+ }
+ return null;
+ }
+
+ /**
+ *
+ * {@inheritedDoc}
+ */
+ @Override
+ public void notifyChanged(Notification notification) {
+ refreshDisplay();
+ }
+
+ /**
+ * this method creates a node for the compartment of stereotype if it does not exist.
+ *
+ * @param stereotypeApplication
+ * the stereotype application
+ */
+ public void createShapeCompartment() {
+ final IGraphicalEditPart editPart = (IGraphicalEditPart) getHost();
+ final View node = editPart.getNotationView();
+ // Look for the node for the shape compartment
+ View shapeCompartment = getShapeCompartmentView(node);
+ // it does not exist
+ if (shapeCompartment == null) {
+ executeShapeCompartmentCreation(editPart);
+ }
+ }
+
+ /**
+ * Returns the view corresponding to the shape compartment
+ *
+ * @param node
+ * @return
+ */
+ private View getShapeCompartmentView(View node) {
+ for (Object child : node.getChildren()) {
+ if (child instanceof View && IShapeCompartmentEditPart.VIEW_TYPE.equals(((View) child).getType())) {
+ return (View) child;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * the goal of this method is to execute the a command to create a notation node for a compartment of stereotype
+ *
+ * @param editPart
+ * the editpart owner of the new compartment
+ * @param appliedstereotype
+ * the stereotype application
+ */
+ protected void setVisibility(final View view, final boolean isVisible) {
+ final GraphicalEditPart editPart = (GraphicalEditPart) getHost();
+ Display.getCurrent().asyncExec(new Runnable() {
+
+ @Override
+ public void run() {
+ SetNodeVisibilityCommand setCommand = new SetNodeVisibilityCommand(editPart.getEditingDomain(), view, isVisible);
+ // use to avoid to put it in the command stack
+ execute(setCommand);
+ }
+ });
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java
index cf0406e747a..5d9f35974c4 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/editpolicies/XYLayoutWithConstrainedResizedEditPolicy.java
@@ -1,300 +1,300 @@
-/*****************************************************************************
- * Copyright (c) 2014 - 2017 CEA LIST.
- *
- * 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:
- *
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * C�line Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 520154
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.NodeEditPart;
-import org.eclipse.gef.SnapToHelper;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.requests.CreateRequest;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
-import org.eclipse.gmf.runtime.diagram.ui.figures.LayoutHelper;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.gmfdiag.common.commands.FixEdgeAnchorsDeferredCommand;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ConnectionEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.FixAnchorHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
-
-/**
- *
- * This edit policy allows to resize parent from NORTH, NORTH_WEST or WEST without moving its children
- *
- */
-public class XYLayoutWithConstrainedResizedEditPolicy extends XYLayoutEditPolicy {
-
- private FixAnchorHelper helper = null;
-
- /**
- * Overrided {@link org.eclipse.gef.editpolicies.XYLayoutEditPolicy}#getCurrentConstraintFor()
- * to the fixing NPE of parent.getLayoutManager().getConstraint(fig) row
- * parent.getLayoutManager() can be null for edges
- */
- @Override
- protected Rectangle getCurrentConstraintFor(GraphicalEditPart child) {
- if (child instanceof ConnectionEditPart && child.getParent() instanceof DiagramRootEditPart) {
- return null;
- }
- return super.getCurrentConstraintFor(child);
- }
-
- /**
- * Called in response to a <tt>REQ_CREATE</tt> request. Returns a command
- * to set each created element bounds and auto-size properties.
- *
- * @param request
- * a create request (understands instances of {@link CreateViewRequest}).
- * @return a command to satisfy the request; <tt>null</tt> if the request is not
- * understood.
- */
- @Override
- protected Command getCreateCommand(CreateRequest request) {
- CreateViewRequest req = (CreateViewRequest) request;
-
-
- TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
-
- CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);
- Iterator<?> iter = req.getViewDescriptors().iterator();
- final Rectangle BOUNDS = (Rectangle) getConstraintFor(request);
- boolean couldBeSnaped = request.getLocation().equals(LayoutHelper.UNDEFINED.getLocation()) && req.isSnapToEnabled();
- while (iter.hasNext()) {
- CreateViewRequest.ViewDescriptor viewDescriptor = (CreateViewRequest.ViewDescriptor) iter.next();
- Rectangle rect = getBoundsOffest(req, BOUNDS, viewDescriptor);
-
- // see bug 427129: Figures newly created via the palette should be snapped to grid if "snap to grid" is activated
- if (couldBeSnaped) {
- // this code fix the bug in some case...
- int add = 0;
- DiagramRootEditPart drep = (DiagramRootEditPart) getHost().getRoot();
- double spacing = drep.getGridSpacing();
- final double max_value = spacing * 20;
- final SnapToHelper helper = (SnapToHelper) getHost().getAdapter(SnapToHelper.class);
- if (helper != null) {
- final LayoutHelper layoutHelper = new LayoutHelper();
- while (add < max_value) {// we define a max value to do test
- Rectangle LOCAL_BOUNDS = BOUNDS.getCopy();
- LOCAL_BOUNDS.translate(add, add);
- Rectangle tmp_rect = getBoundsOffest(req, LOCAL_BOUNDS, viewDescriptor);
- final PrecisionRectangle resultRect = new PrecisionRectangle(tmp_rect);
- resultRect.setWidth(-1);
- resultRect.setHeight(-1);
- PrecisionPoint res1 = new PrecisionPoint(tmp_rect.getLocation());
- helper.snapPoint(request, PositionConstants.NORTH_WEST, res1.getPreciseCopy(), res1);
- final Point pt = layoutHelper.validatePosition(getHostFigure(), resultRect.setLocation(res1));
- if (couldBeSnaped) {
- if (pt.equals(resultRect.getLocation())) {
- rect.setLocation(resultRect.getLocation());
- break;
- } else {
- add += spacing;
- continue;
- }
- }
- }
- }
- }
-
- // Default set bounds command.
- cc.compose(new SetBoundsCommand(editingDomain, DiagramUIMessages.SetLocationCommand_Label_Resize, viewDescriptor, rect));
- break;
-
- }
-
- if (cc.reduce() == null) {
- return null;
- }
- return chainGuideAttachmentCommands(request, new ICommandProxy(cc.reduce()));
- }
-
-
- /**
- * Returns the <code>Command</code> to resize a group of children.
- *
- * @param request
- * the ChangeBoundsRequest
- * @return the Command
- */
- @Override
- protected Command getChangeConstraintCommand(ChangeBoundsRequest request) {
- final CompoundCommand resize = new CompoundCommand("Resize Command");//$NON-NLS-1$
- IGraphicalEditPart child;
- final List<?> children = request.getEditParts();
- final int direction = request.getResizeDirection();
- boolean isConstrainedResize = request.isConstrainedResize();
- boolean forceLocation = isConstrainedResize;// && (direction == PositionConstants.WEST || direction == PositionConstants.NORTH || direction == PositionConstants.NORTH_WEST );//|| direction == PositionConstants.NORTH_EAST || direction ==
- // PositionConstants.SOUTH_WEST);
- for (int i = 0; i < children.size(); i++) {
- child = (IGraphicalEditPart) children.get(i);
- resize.add(createChangeConstraintCommand(request, child, translateToModelConstraint(getConstraintFor(request, child))));
- final Point move = request.getMoveDelta();
- if (forceLocation) {
- for (Object object : child.getChildren()) {
- if (object instanceof CompartmentEditPart) {
- final EditPolicy layoutPolicy = ((CompartmentEditPart) object).getEditPolicy(EditPolicy.LAYOUT_ROLE);
- if (layoutPolicy instanceof org.eclipse.gef.editpolicies.XYLayoutEditPolicy) {
- for (final Object current : ((CompartmentEditPart) object).getChildren()) {
- if (current instanceof NodeEditPart) {
- final ChangeBoundsRequest forceLocationRequest = new ChangeBoundsRequest();
- forceLocationRequest.setType("move");//$NON-NLS-1$
- forceLocationRequest.setMoveDelta(move.getNegated());
- forceLocationRequest.setEditParts((EditPart) current);
- final Command tmp = ((NodeEditPart) current).getCommand(forceLocationRequest);
- if (tmp != null) {
- resize.add(tmp);
- }
- }
- }
- }
- }
- }
- }
- // we add the command to fix the anchor
- if (isConstrainedResize && child instanceof INodeEditPart) {
- if (getHelper() == null) {
- TransactionalEditingDomain domain = null;
- try {
- domain = ServiceUtilsForEditPart.getInstance().getTransactionalEditingDomain(child);
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- setHelper(new FixAnchorHelper(domain));
- }
- final Command fixAnchorCommand = getHelper().getFixIdentityAnchorCommand((INodeEditPart) child, request.getMoveDelta(), request.getSizeDelta(), request.getResizeDirection());
- if (fixAnchorCommand != null) {
- resize.add(fixAnchorCommand);
- }
- }
- }
- return resize.unwrap();
- }
-
- /**
- * @return the helper
- * @since 3.1
- */
- public FixAnchorHelper getHelper() {
- return helper;
- }
-
- /**
- * @param helper
- * the helper to set
- * @since 3.1
- */
- public void setHelper(FixAnchorHelper helper) {
- this.helper = helper;
- }
-
- @Override
- protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
- final Command cmd = super.createChangeConstraintCommand(request, child, constraint);
- if (org.eclipse.gef.RequestConstants.REQ_MOVE_CHILDREN.equals(request.getType()) && child instanceof INodeEditPart) {
- Set<Object> notBeingMovedConnections = getConnectionsToElementsNotBeingMoved(request, child);
- if (!notBeingMovedConnections.isEmpty()) {
- final CompoundCommand cc = new CompoundCommand();
- cc.add(cmd);
- // see bug 430702: [Diagram] Moving source of a link moves the target too.
- ICommandProxy moveChildrenFixEdgeAnchorCommand = getMoveChildrenFixEdgeAnchorCommand(notBeingMovedConnections);
- if (null != moveChildrenFixEdgeAnchorCommand) {
- cc.add(moveChildrenFixEdgeAnchorCommand);
- }
- return cc;
- }
- }
- return cmd;
- }
-
- /**
- * Get the Command to Fix the Edge Anchor when moving the children
- *
- * @param notBeingMovedConnections
- * List of not being moved Connections
- * @return The proxy Command to Fix the Edge Anchor
- * @since 3.1
- */
- protected ICommandProxy getMoveChildrenFixEdgeAnchorCommand(Set<Object> notBeingMovedConnections) {
- return new ICommandProxy(new FixEdgeAnchorsDeferredCommand(getEditingDomain(), (IGraphicalEditPart) getHost(), notBeingMovedConnections));
- }
-
- /*
- * {@link FixEdgeAnchorsDeferredCommand} should not be applied to the multiple selection move request
- * see Bug 459839 - [All Diagrams] unexpected behavior moving multiple linked elements
- */
- private Set<Object> getConnectionsToElementsNotBeingMoved(ChangeBoundsRequest request, EditPart child) {
- List<?> sources = ((INodeEditPart) child).getSourceConnections();
- List<?> targets = ((INodeEditPart) child).getTargetConnections();
- Set<Object> connections = new HashSet<Object>();
- connections.addAll(sources);
- connections.addAll(targets);
- if (connections.isEmpty()) {
- return Collections.emptySet();
- }
- PapyrusResizableShapeEditPolicy.CachedEditPartsSet movedEditPartsSet = PapyrusResizableShapeEditPolicy.getMovedEditPartsSet(request);
- final Set<Object> result = new HashSet<Object>();
- final Iterator<?> connectionsIter = connections.iterator();
- while (connectionsIter.hasNext()) {
- final Object nextConnection = connectionsIter.next();
- if (false == nextConnection instanceof AbstractConnectionEditPart) {
- continue;
- }
- AbstractConnectionEditPart nextTypedConnection = (AbstractConnectionEditPart) nextConnection;
- EditPart sourceEnd = nextTypedConnection.getSource();
- EditPart targetEnd = nextTypedConnection.getTarget();
- if (movedEditPartsSet.isMovedEditPart(sourceEnd) && movedEditPartsSet.isMovedEditPart(targetEnd)) {
- continue;
- }
- result.add(nextConnection);
- }
- return result;
- }
-
- protected TransactionalEditingDomain getEditingDomain() {
-
- TransactionalEditingDomain domain = null;
- try {
- domain = ServiceUtilsForEditPart.getInstance().getTransactionalEditingDomain(getHost());
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- return domain;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 - 2017 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * C�line Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 520154
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.editpolicies;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.NodeEditPart;
+import org.eclipse.gef.SnapToHelper;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.requests.CreateRequest;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editpolicies.XYLayoutEditPolicy;
+import org.eclipse.gmf.runtime.diagram.ui.figures.LayoutHelper;
+import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramUIMessages;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.emf.commands.core.command.CompositeTransactionalCommand;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.common.commands.FixEdgeAnchorsDeferredCommand;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ConnectionEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.FixAnchorHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+
+/**
+ *
+ * This edit policy allows to resize parent from NORTH, NORTH_WEST or WEST without moving its children
+ *
+ */
+public class XYLayoutWithConstrainedResizedEditPolicy extends XYLayoutEditPolicy {
+
+ private FixAnchorHelper helper = null;
+
+ /**
+ * Overrided {@link org.eclipse.gef.editpolicies.XYLayoutEditPolicy}#getCurrentConstraintFor()
+ * to the fixing NPE of parent.getLayoutManager().getConstraint(fig) row
+ * parent.getLayoutManager() can be null for edges
+ */
+ @Override
+ protected Rectangle getCurrentConstraintFor(GraphicalEditPart child) {
+ if (child instanceof ConnectionEditPart && child.getParent() instanceof DiagramRootEditPart) {
+ return null;
+ }
+ return super.getCurrentConstraintFor(child);
+ }
+
+ /**
+ * Called in response to a <tt>REQ_CREATE</tt> request. Returns a command
+ * to set each created element bounds and auto-size properties.
+ *
+ * @param request
+ * a create request (understands instances of {@link CreateViewRequest}).
+ * @return a command to satisfy the request; <tt>null</tt> if the request is not
+ * understood.
+ */
+ @Override
+ protected Command getCreateCommand(CreateRequest request) {
+ CreateViewRequest req = (CreateViewRequest) request;
+
+
+ TransactionalEditingDomain editingDomain = ((IGraphicalEditPart) getHost()).getEditingDomain();
+
+ CompositeTransactionalCommand cc = new CompositeTransactionalCommand(editingDomain, DiagramUIMessages.AddCommand_Label);
+ Iterator<?> iter = req.getViewDescriptors().iterator();
+ final Rectangle BOUNDS = (Rectangle) getConstraintFor(request);
+ boolean couldBeSnaped = request.getLocation().equals(LayoutHelper.UNDEFINED.getLocation()) && req.isSnapToEnabled();
+ while (iter.hasNext()) {
+ CreateViewRequest.ViewDescriptor viewDescriptor = (CreateViewRequest.ViewDescriptor) iter.next();
+ Rectangle rect = getBoundsOffest(req, BOUNDS, viewDescriptor);
+
+ // see bug 427129: Figures newly created via the palette should be snapped to grid if "snap to grid" is activated
+ if (couldBeSnaped) {
+ // this code fix the bug in some case...
+ int add = 0;
+ DiagramRootEditPart drep = (DiagramRootEditPart) getHost().getRoot();
+ double spacing = drep.getGridSpacing();
+ final double max_value = spacing * 20;
+ final SnapToHelper helper = (SnapToHelper) getHost().getAdapter(SnapToHelper.class);
+ if (helper != null) {
+ final LayoutHelper layoutHelper = new LayoutHelper();
+ while (add < max_value) {// we define a max value to do test
+ Rectangle LOCAL_BOUNDS = BOUNDS.getCopy();
+ LOCAL_BOUNDS.translate(add, add);
+ Rectangle tmp_rect = getBoundsOffest(req, LOCAL_BOUNDS, viewDescriptor);
+ final PrecisionRectangle resultRect = new PrecisionRectangle(tmp_rect);
+ resultRect.setWidth(-1);
+ resultRect.setHeight(-1);
+ PrecisionPoint res1 = new PrecisionPoint(tmp_rect.getLocation());
+ helper.snapPoint(request, PositionConstants.NORTH_WEST, res1.getPreciseCopy(), res1);
+ final Point pt = layoutHelper.validatePosition(getHostFigure(), resultRect.setLocation(res1));
+ if (couldBeSnaped) {
+ if (pt.equals(resultRect.getLocation())) {
+ rect.setLocation(resultRect.getLocation());
+ break;
+ } else {
+ add += spacing;
+ continue;
+ }
+ }
+ }
+ }
+ }
+
+ // Default set bounds command.
+ cc.compose(new SetBoundsCommand(editingDomain, DiagramUIMessages.SetLocationCommand_Label_Resize, viewDescriptor, rect));
+ break;
+
+ }
+
+ if (cc.reduce() == null) {
+ return null;
+ }
+ return chainGuideAttachmentCommands(request, new ICommandProxy(cc.reduce()));
+ }
+
+
+ /**
+ * Returns the <code>Command</code> to resize a group of children.
+ *
+ * @param request
+ * the ChangeBoundsRequest
+ * @return the Command
+ */
+ @Override
+ protected Command getChangeConstraintCommand(ChangeBoundsRequest request) {
+ final CompoundCommand resize = new CompoundCommand("Resize Command");//$NON-NLS-1$
+ IGraphicalEditPart child;
+ final List<?> children = request.getEditParts();
+ final int direction = request.getResizeDirection();
+ boolean isConstrainedResize = request.isConstrainedResize();
+ boolean forceLocation = isConstrainedResize;// && (direction == PositionConstants.WEST || direction == PositionConstants.NORTH || direction == PositionConstants.NORTH_WEST );//|| direction == PositionConstants.NORTH_EAST || direction ==
+ // PositionConstants.SOUTH_WEST);
+ for (int i = 0; i < children.size(); i++) {
+ child = (IGraphicalEditPart) children.get(i);
+ resize.add(createChangeConstraintCommand(request, child, translateToModelConstraint(getConstraintFor(request, child))));
+ final Point move = request.getMoveDelta();
+ if (forceLocation) {
+ for (Object object : child.getChildren()) {
+ if (object instanceof CompartmentEditPart) {
+ final EditPolicy layoutPolicy = ((CompartmentEditPart) object).getEditPolicy(EditPolicy.LAYOUT_ROLE);
+ if (layoutPolicy instanceof org.eclipse.gef.editpolicies.XYLayoutEditPolicy) {
+ for (final Object current : ((CompartmentEditPart) object).getChildren()) {
+ if (current instanceof NodeEditPart) {
+ final ChangeBoundsRequest forceLocationRequest = new ChangeBoundsRequest();
+ forceLocationRequest.setType("move");//$NON-NLS-1$
+ forceLocationRequest.setMoveDelta(move.getNegated());
+ forceLocationRequest.setEditParts((EditPart) current);
+ final Command tmp = ((NodeEditPart) current).getCommand(forceLocationRequest);
+ if (tmp != null) {
+ resize.add(tmp);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ // we add the command to fix the anchor
+ if (isConstrainedResize && child instanceof INodeEditPart) {
+ if (getHelper() == null) {
+ TransactionalEditingDomain domain = null;
+ try {
+ domain = ServiceUtilsForEditPart.getInstance().getTransactionalEditingDomain(child);
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ setHelper(new FixAnchorHelper(domain));
+ }
+ final Command fixAnchorCommand = getHelper().getFixIdentityAnchorCommand((INodeEditPart) child, request.getMoveDelta(), request.getSizeDelta(), request.getResizeDirection());
+ if (fixAnchorCommand != null) {
+ resize.add(fixAnchorCommand);
+ }
+ }
+ }
+ return resize.unwrap();
+ }
+
+ /**
+ * @return the helper
+ * @since 3.1
+ */
+ public FixAnchorHelper getHelper() {
+ return helper;
+ }
+
+ /**
+ * @param helper
+ * the helper to set
+ * @since 3.1
+ */
+ public void setHelper(FixAnchorHelper helper) {
+ this.helper = helper;
+ }
+
+ @Override
+ protected Command createChangeConstraintCommand(ChangeBoundsRequest request, EditPart child, Object constraint) {
+ final Command cmd = super.createChangeConstraintCommand(request, child, constraint);
+ if (org.eclipse.gef.RequestConstants.REQ_MOVE_CHILDREN.equals(request.getType()) && child instanceof INodeEditPart) {
+ Set<Object> notBeingMovedConnections = getConnectionsToElementsNotBeingMoved(request, child);
+ if (!notBeingMovedConnections.isEmpty()) {
+ final CompoundCommand cc = new CompoundCommand();
+ cc.add(cmd);
+ // see bug 430702: [Diagram] Moving source of a link moves the target too.
+ ICommandProxy moveChildrenFixEdgeAnchorCommand = getMoveChildrenFixEdgeAnchorCommand(notBeingMovedConnections);
+ if (null != moveChildrenFixEdgeAnchorCommand) {
+ cc.add(moveChildrenFixEdgeAnchorCommand);
+ }
+ return cc;
+ }
+ }
+ return cmd;
+ }
+
+ /**
+ * Get the Command to Fix the Edge Anchor when moving the children
+ *
+ * @param notBeingMovedConnections
+ * List of not being moved Connections
+ * @return The proxy Command to Fix the Edge Anchor
+ * @since 3.1
+ */
+ protected ICommandProxy getMoveChildrenFixEdgeAnchorCommand(Set<Object> notBeingMovedConnections) {
+ return new ICommandProxy(new FixEdgeAnchorsDeferredCommand(getEditingDomain(), (IGraphicalEditPart) getHost(), notBeingMovedConnections));
+ }
+
+ /*
+ * {@link FixEdgeAnchorsDeferredCommand} should not be applied to the multiple selection move request
+ * see Bug 459839 - [All Diagrams] unexpected behavior moving multiple linked elements
+ */
+ private Set<Object> getConnectionsToElementsNotBeingMoved(ChangeBoundsRequest request, EditPart child) {
+ List<?> sources = ((INodeEditPart) child).getSourceConnections();
+ List<?> targets = ((INodeEditPart) child).getTargetConnections();
+ Set<Object> connections = new HashSet<Object>();
+ connections.addAll(sources);
+ connections.addAll(targets);
+ if (connections.isEmpty()) {
+ return Collections.emptySet();
+ }
+ PapyrusResizableShapeEditPolicy.CachedEditPartsSet movedEditPartsSet = PapyrusResizableShapeEditPolicy.getMovedEditPartsSet(request);
+ final Set<Object> result = new HashSet<Object>();
+ final Iterator<?> connectionsIter = connections.iterator();
+ while (connectionsIter.hasNext()) {
+ final Object nextConnection = connectionsIter.next();
+ if (false == nextConnection instanceof AbstractConnectionEditPart) {
+ continue;
+ }
+ AbstractConnectionEditPart nextTypedConnection = (AbstractConnectionEditPart) nextConnection;
+ EditPart sourceEnd = nextTypedConnection.getSource();
+ EditPart targetEnd = nextTypedConnection.getTarget();
+ if (movedEditPartsSet.isMovedEditPart(sourceEnd) && movedEditPartsSet.isMovedEditPart(targetEnd)) {
+ continue;
+ }
+ result.add(nextConnection);
+ }
+ return result;
+ }
+
+ protected TransactionalEditingDomain getEditingDomain() {
+
+ TransactionalEditingDomain domain = null;
+ try {
+ domain = ServiceUtilsForEditPart.getInstance().getTransactionalEditingDomain(getHost());
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ return domain;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java
index 1aa7ead09c7..b9f533cd4c7 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/IPapyrusWrappingLabel.java
@@ -1,46 +1,46 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST 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:
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.figure;
-
-import org.eclipse.draw2d.IFigure;
-
-/**
- * @author Céline JANSSENS
- * Bug 440230
- * This interface is dedicated to PapyrusWrappingLabel abstract methods.
- *
- */
-public interface IPapyrusWrappingLabel extends IFigure {
-
- /**
- * Set the margin of the Label in the horizontal direction and vertical Direction
- * @param xMargin Horizontal Margin
- * @param yMargin Vertical Margin
- *
- */
- void setMarginLabel(int xMargin , int yMargin);
-
-
-
-
-
- /**
- * Set the margin of the Label in the horizontal direction and vertical Direction
- * @param xMargin Horizontal Margin
- * @param yMargin Vertical Margin
- *
- */
- void setMarginLabel(int leftMargin , int topMargin, int rightMargin, int bottomMargin);
-
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST 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:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.figure;
+
+import org.eclipse.draw2d.IFigure;
+
+/**
+ * @author Céline JANSSENS
+ * Bug 440230
+ * This interface is dedicated to PapyrusWrappingLabel abstract methods.
+ *
+ */
+public interface IPapyrusWrappingLabel extends IFigure {
+
+ /**
+ * Set the margin of the Label in the horizontal direction and vertical Direction
+ * @param xMargin Horizontal Margin
+ * @param yMargin Vertical Margin
+ *
+ */
+ void setMarginLabel(int xMargin , int yMargin);
+
+
+
+
+
+ /**
+ * Set the margin of the Label in the horizontal direction and vertical Direction
+ * @param xMargin Horizontal Margin
+ * @param yMargin Vertical Margin
+ *
+ */
+ void setMarginLabel(int leftMargin , int topMargin, int rightMargin, int bottomMargin);
+
} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/SlidableEllipseAnchor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/SlidableEllipseAnchor.java
index 811aa0cf243..fca5a1c1a19 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/SlidableEllipseAnchor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/SlidableEllipseAnchor.java
@@ -1,77 +1,77 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.figure;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PointList;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
-import org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor;
-
-
-/**
- * this code comes from eclipse.
- * I have change the figure IOvalAnchorableFigure by Ifigure for the constructor
- *
- * @author oboyko
- *
- * Window - Preferences - Java - Code Style - Code Templates
- */
-public class SlidableEllipseAnchor extends SlidableAnchor {
-
- /**
- * Default constructor
- */
- public SlidableEllipseAnchor() {
- super();
- }
-
- /**
- * Creates default <Code>SlidableOvalAnchor</Code> with a reference points
- * at the center of the figure
- *
- * @param f
- * the figure that this anchor will be associated with
- */
- public SlidableEllipseAnchor(IFigure f) {
- super(f);
- }
-
- /**
- * Creates <Code>SlidableOvalAnchor</Code> with a specified reference points
- *
- * @param f
- * the figure that this anchor will be associated with
- * @param p
- * the <code>PrecisionPoint</code> that the anchor will initially attach to.
- */
- public SlidableEllipseAnchor(IFigure f, PrecisionPoint p) {
- super(f, p);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor#getIntersectionPoints(org.eclipse.draw2d.geometry.Point, org.eclipse.draw2d.geometry.Point)
- */
- @Override
- protected PointList getIntersectionPoints(Point ownReference, Point foreignReference) {
- Rectangle ellipseBox = new PrecisionRectangle(getOwner().getBounds());
- getOwner().translateToAbsolute(ellipseBox);
- return (new LineSeg(ownReference, foreignReference)).getLineIntersectionsWithEllipse(ellipseBox);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.figure;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
+import org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor;
+
+
+/**
+ * this code comes from eclipse.
+ * I have change the figure IOvalAnchorableFigure by Ifigure for the constructor
+ *
+ * @author oboyko
+ *
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class SlidableEllipseAnchor extends SlidableAnchor {
+
+ /**
+ * Default constructor
+ */
+ public SlidableEllipseAnchor() {
+ super();
+ }
+
+ /**
+ * Creates default <Code>SlidableOvalAnchor</Code> with a reference points
+ * at the center of the figure
+ *
+ * @param f
+ * the figure that this anchor will be associated with
+ */
+ public SlidableEllipseAnchor(IFigure f) {
+ super(f);
+ }
+
+ /**
+ * Creates <Code>SlidableOvalAnchor</Code> with a specified reference points
+ *
+ * @param f
+ * the figure that this anchor will be associated with
+ * @param p
+ * the <code>PrecisionPoint</code> that the anchor will initially attach to.
+ */
+ public SlidableEllipseAnchor(IFigure f, PrecisionPoint p) {
+ super(f, p);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor#getIntersectionPoints(org.eclipse.draw2d.geometry.Point, org.eclipse.draw2d.geometry.Point)
+ */
+ @Override
+ protected PointList getIntersectionPoints(Point ownReference, Point foreignReference) {
+ Rectangle ellipseBox = new PrecisionRectangle(getOwner().getBounds());
+ getOwner().translateToAbsolute(ellipseBox);
+ return (new LineSeg(ownReference, foreignReference)).getLineIntersectionsWithEllipse(ellipseBox);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
index 5fbe68c46d1..95b2637decc 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/edge/PapyrusEdgeFigure.java
@@ -1,450 +1,450 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.edge;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.eclipse.draw2d.Connection;
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PointList;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalViewer;
-import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
-import org.eclipse.gmf.runtime.common.ui.services.editor.EditorService;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
-import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
-import org.eclipse.papyrus.infra.ui.editor.CoreMultiDiagramEditor;
-import org.eclipse.papyrus.infra.ui.util.EditorHelper;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-
-/**
- *
- * This class should be the super class of all Papyrus figure.
- * Its provides the way to draw common bendpoints bigger than others
- *
- */
-public abstract class PapyrusEdgeFigure extends PolylineConnectionEx {
-
- /**
- * Diameter to use for the bendpoitns
- */
- private int bendpointDiameter;
-
- /**
- *
- * Constructor.
- *
- */
- public PapyrusEdgeFigure() {
- super();
- setBendPointDiameter(7);
- }
-
- /**
- * We override this method to circle on bendpoints when a segment of the link is shared with another link of the same kind
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx#outlineShape(org.eclipse.draw2d.Graphics)
- *
- * @param g
- */
- @Override
- protected void outlineShape(Graphics g) {
- super.outlineShape(g);
- drawCommonbendpoints(g);
- }
-
- /**
- * Resets the style of this figure to its default implementation
- */
- public void resetStyle() {
-
- }
-
- /**
- *
- * @return
- * the common bendpoints to draw (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=424099)
- */
- @SuppressWarnings("unchecked")
- public Collection<Point> getCommonBendpointsToDraw() {
- final Collection<Point> commonBendpointsToDraw = new HashSet<Point>();
- final PointList bendPoints = getPoints();
-
- final Map<?, ?> visualPartMap = getVisualPartMap(this);
- if (visualPartMap != null) {
- final EditPart currentEditPart = (EditPart) visualPartMap.get(this);
- // 1. find the uml eClass of the current link
- EClass eClass = null;
- if (currentEditPart instanceof IGraphicalEditPart) {
- final EObject el = ((IGraphicalEditPart) currentEditPart).resolveSemanticElement();
- if (el != null) {
- eClass = el.eClass();
- }
- }
-
- // 2. find all connections editpart with same source AND/OR same target than the current one
- if (currentEditPart instanceof ConnectionEditPart && eClass != null) {
- final EditPart sourceEP = ((ConnectionEditPart) currentEditPart).getSource();
- final EditPart targetEP = ((ConnectionEditPart) currentEditPart).getTarget();
- final Set<Object> allConnectionsEP = new HashSet<Object>();
- // 2.1. get all potential editpart connections
- if (sourceEP instanceof AbstractGraphicalEditPart && targetEP instanceof AbstractGraphicalEditPart) {
- allConnectionsEP.addAll(((AbstractGraphicalEditPart) sourceEP).getSourceConnections());
- allConnectionsEP.addAll(((AbstractGraphicalEditPart) targetEP).getSourceConnections());
- allConnectionsEP.addAll(((AbstractGraphicalEditPart) sourceEP).getTargetConnections());
- allConnectionsEP.addAll(((AbstractGraphicalEditPart) targetEP).getTargetConnections());
- allConnectionsEP.remove(currentEditPart);
- }
-
- // 2.2 get the figure for these connections and keep only figure when its editpart has the same kind than the current one
- final Set<Connection> allConnections = new HashSet<Connection>();
- if (allConnectionsEP.size() > 0) {
- for (final Object current : allConnectionsEP) {
- // the editpart be instance of the same class
- if (current.getClass().isInstance(currentEditPart) && currentEditPart.getClass().isInstance(current) && current instanceof IGraphicalEditPart) {
- final EObject resolvedElement = ((IGraphicalEditPart) current).resolveSemanticElement();
- if (resolvedElement != null && eClass != null && resolvedElement.eClass() != eClass) {
- continue;// we draw ben point only for elements which have the same eClass, when this eClass is not null
- }
- final IFigure currentFig = ((IGraphicalEditPart) current).getFigure();
- if (currentFig instanceof Connection) {
- allConnections.add((Connection) currentFig);
- }
- }
- }
- }
-
- // 3. Create the list of the LineSeg of the current figure
- final List<LineSeg> refs = new ArrayList<LineSeg>();
- for (int i = 0; i < bendPoints.size() - 1; i++) {
- LineSeg seg = new LineSeg(bendPoints.getPoint(i), bendPoints.getPoint(i + 1));
- refs.add(seg);
- }
-
-
- // 4. find common segments between the current figure and each others link
- // we need to associate each common segment to the concerned link
- final Map<Connection, Map<LineSeg, List<LineSeg>>> segs = new HashMap<Connection, Map<LineSeg, List<LineSeg>>>();
- for (Connection currentConn : allConnections) {
- final PointList currentPoints = currentConn.getPoints();
- final Map<LineSeg, List<LineSeg>> mapSegs = new HashMap<LineSeg, List<LineSeg>>();
- segs.put(currentConn, mapSegs);
- for (LineSeg refSeg : refs) {
- final List<LineSeg> commonSubSegs = new ArrayList<LineSeg>();
- mapSegs.put(refSeg, commonSubSegs);
- for (int i = 0; i < currentPoints.size() - 1; i++) {
- LineSeg tmp = new LineSeg(currentPoints.getPoint(i), currentPoints.getPoint(i + 1));
- PointList intersection = getCommonSegment(refSeg, tmp);
- if (intersection.size() == 2) {
- if (!intersection.getFirstPoint().equals(intersection.getLastPoint())) {
- double distanceFromFirst = refSeg.getOrigin().getDistance(intersection.getFirstPoint());
- double distanceFromSecond = refSeg.getOrigin().getDistance(intersection.getLastPoint());
- final LineSeg commonSeg;
- // we arrange the 2 points in order to have the first point nearest of the start of the current segment
- if (distanceFromFirst < distanceFromSecond) {
- commonSeg = new LineSeg(intersection.getFirstPoint(), intersection.getLastPoint());
- } else {
- commonSeg = new LineSeg(intersection.getLastPoint(), intersection.getFirstPoint());
- }
- commonSubSegs.add(commonSeg);
- }
- }
- }
- }
- }
-
- // 5. we look for the bendpoints crossing existing link on the model, then crossing their common segment with the current figure, to find bendpoints to draw
- for (Entry<Connection, Map<LineSeg, List<LineSeg>>> entry : segs.entrySet()) {
- final Map<LineSeg, List<LineSeg>> commonSegMap = entry.getValue();
- for (int i = 0; i < refs.size(); i++) { // we iterate on the segments of the current figure
-
-
- // 5.1 find required values to find bendpoints to draw
- final LineSeg currentFigureSeg = refs.get(i);
- // final List<LineSeg> currentCommonSegs = segs.get(currentFigureSeg);
- final List<LineSeg> currentCommonSegs = commonSegMap.get(currentFigureSeg);
-
- final LineSeg previousSeg;
- final List<LineSeg> previousCommonSegs;
-
- final LineSeg nextSeg;
- final List<LineSeg> nextCommonSegs;
-
- // obtain previous segs of the current figure
- if (i != 0) {
- previousSeg = refs.get(i - 1);
- previousCommonSegs = commonSegMap.get(previousSeg);
- } else {
- previousSeg = null;
- previousCommonSegs = null;
- }
-
- // obtain next segs of the current figure
- if (i != refs.size() - 1) {
- nextSeg = refs.get(i + 1);
- nextCommonSegs = commonSegMap.get(nextSeg);
- } else {
- nextSeg = null;
- nextCommonSegs = null;
- }
-
-
- LineSeg previousCommonSeg = null;
- LineSeg nextCommonSeg = null;
-
- // we iterate on the common subsegment shared with others link with the current figure
- for (int a = 0; a < currentCommonSegs.size(); a++) {
- final LineSeg curr = currentCommonSegs.get(a);
- final Point first = curr.getOrigin();
- final Point second = curr.getTerminus();
- // obtain previous common seg
- if (a == 0) {
- if (previousCommonSegs != null && previousCommonSegs.size() > 0) {
- previousCommonSeg = previousCommonSegs.get(previousCommonSegs.size() - 1);
- } else {
- previousCommonSeg = null;
- }
- } else {
- previousCommonSeg = currentCommonSegs.get(a - 1);
- }
-
- // obtain next common seg
- if (a == currentCommonSegs.size() - 1) {
- if (nextCommonSegs != null && nextCommonSegs.size() > 0) {
- nextCommonSeg = nextCommonSegs.get(0);
- } else {
- nextCommonSeg = null;
- }
- } else {
- nextCommonSeg = currentCommonSegs.get(a + 1);
- }
-
- // 5.2 calculates bendpoints visibility
-
- // determining if we draw first point :
- if (previousCommonSeg == null) {
- if (i == 0) {// first segment of the figure
- if (!bendPoints.getFirstPoint().equals(first)) {
- // we draw the point when it is not the first anchor of the figure
- commonBendpointsToDraw.add(first);
- }
- } else {
- commonBendpointsToDraw.add(first);
- }
- } else if (!previousCommonSeg.getTerminus().equals(first)) {
- // the previous common seg doesn't share this point with the current segment
- // we draw the first point
- commonBendpointsToDraw.add(first);
- }
-
- // determining if we draw the second point
- if (nextCommonSeg == null) {
- if (i == refs.size() - 1) {
- if (!bendPoints.getLastPoint().equals(second)) {
- // we draw the point when it is not the first anchor of the figure
- commonBendpointsToDraw.add(second);
- }
- } else {
- commonBendpointsToDraw.add(second);
- }
- } else if (!nextCommonSeg.getOrigin().equals(second)) {
- // the next common seg doesn't share this point with the current segment
- // we draw the second point
- commonBendpointsToDraw.add(second);
- }
- }
- }
- }
- }
- }
-
- return commonBendpointsToDraw;
- }
-
- /**
- *
- * @param g
- * graphics
- * @param pointsToDraw
- * the list of the points to draw
- */
- public void drawCommonBendpoints(final Graphics g, final Collection<Point> bendPoints) {
- final int diameter = getBendPointDiameter();
- if (getDrawBendpointPreferenceValue() && bendPoints.size() > 0 && diameter > 1) {
- // initialize the graphics
- if (getBackgroundColor() != null) {
- g.setForegroundColor(getBackgroundColor());
- }
- if (getForegroundColor() != null) {
- g.setBackgroundColor(getForegroundColor());
- }
-
- for (final Point point : bendPoints) {
- g.fillOval(point.x - (diameter - 1) / 2, point.y - (diameter - 1) / 2, diameter, diameter);
- }
-
- // reset the graphics
- if (getBackgroundColor() != null) {
- g.setBackgroundColor(getBackgroundColor());
- }
- if (getForegroundColor() != null) {
- g.setForegroundColor(getForegroundColor());
- }
- }
- }
-
-
-
- /**
- *
- * @param g
- *
- */
- protected void drawCommonbendpoints(final Graphics g) {
- if (getPoints().size() > 2 && getDrawBendpointPreferenceValue()) {
- final Collection<Point> commonPoints = getCommonBendpointsToDraw();
- drawCommonBendpoints(g, commonPoints);
- }
- }
-
-
-
- /**
- *
- * @return
- * <code>true</code> according to the preference store
- */
- protected boolean getDrawBendpointPreferenceValue() {
- return false;
- }
-
- /**
- *
- * @param figure
- * a figure
- * @return
- * the visual part map for this figure or <code>null</code> if not found
- */
- protected Map<?, ?> getVisualPartMap(final IFigure figure) {
- IEditorPart part = EditorHelper.getCurrentEditor();
- if (part instanceof CoreMultiDiagramEditor) {
- final List<IEditorPart> visibleEditors = ((CoreMultiDiagramEditor) part).getISashWindowsContainer().getVisibleIEditorParts();
- for (final IEditorPart current : visibleEditors) {
- final GraphicalViewer viewer = (GraphicalViewer) current.getAdapter(GraphicalViewer.class);
- final Map<?, ?> visualPartMap = viewer.getVisualPartMap();
- if (visualPartMap.containsKey(figure)) {
- return visualPartMap;
- }
- }
- } else {
- // used when papyrus has been "unsashified"
- final IWorkbench workbench = PlatformUI.getWorkbench();
- if (workbench != null) {
- final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
- if (window != null) {
- final List<?> editors = EditorService.getInstance().getRegisteredEditorParts();
- for (Iterator<?> j = editors.iterator(); j.hasNext();) {
- final IEditorPart editor = (IEditorPart) j.next();
- if (editor.getEditorSite().getWorkbenchWindow() == window) {
- if (editor instanceof IDiagramWorkbenchPart) {
- final IDiagramWorkbenchPart de = (IDiagramWorkbenchPart) editor;
- final GraphicalViewer viewer = de.getDiagramGraphicalViewer();
- final Map<?, ?> visualPartMap = viewer.getVisualPartMap();
- if (visualPartMap.containsKey(figure)) {
- return visualPartMap;
- }
- }
- }
- }
- }
- }
- }
- return null;
- }
-
- /**
- *
- * @param seg1
- * the first segment
- * @param seg2
- * the secong segment
- * @return
- */
- public static final PointList getCommonSegment(final LineSeg seg1, final LineSeg seg2) {
- final List<Point> list = new ArrayList<Point>();
- list.add(seg1.getOrigin());
- list.add(seg2.getOrigin());
- list.add(seg1.getTerminus());
- list.add(seg2.getTerminus());
-
- List<Point> commonPoints = new ArrayList<Point>();
- for (Point point : list) {
- if (!commonPoints.contains(point)) {
- if (seg1.containsPoint(point, 0) && seg2.containsPoint(point, 0)) {
- commonPoints.add(point);
- }
- }
- }
-
- final PointList result = new PointList();
- for (final Point point : commonPoints) {
- result.addPoint(point);
- }
- return result;
- }
-
- /**
- * Calculate the best diameter and set the diameter value
- *
- * @param diameter
- * the diameter of the bendpoints (if diameter<=1, we set the diameter to 0)
- */
- public void setBendPointDiameter(final int diameter) {
- if (diameter <= 1) {
- this.bendpointDiameter = 0;
- }
- if (diameter % 2 != 0) {
- this.bendpointDiameter = diameter;
- } else {
- setBendPointDiameter(diameter + 1);
- }
- }
-
- /**
- *
- * @return
- * the bendpoint diameter
- */
- protected final int getBendPointDiameter() {
- return this.bendpointDiameter;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.edge;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.editparts.AbstractGraphicalEditPart;
+import org.eclipse.gmf.runtime.common.ui.services.editor.EditorService;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
+import org.eclipse.gmf.runtime.draw2d.ui.geometry.LineSeg;
+import org.eclipse.papyrus.infra.ui.editor.CoreMultiDiagramEditor;
+import org.eclipse.papyrus.infra.ui.util.EditorHelper;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+
+/**
+ *
+ * This class should be the super class of all Papyrus figure.
+ * Its provides the way to draw common bendpoints bigger than others
+ *
+ */
+public abstract class PapyrusEdgeFigure extends PolylineConnectionEx {
+
+ /**
+ * Diameter to use for the bendpoitns
+ */
+ private int bendpointDiameter;
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ public PapyrusEdgeFigure() {
+ super();
+ setBendPointDiameter(7);
+ }
+
+ /**
+ * We override this method to circle on bendpoints when a segment of the link is shared with another link of the same kind
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx#outlineShape(org.eclipse.draw2d.Graphics)
+ *
+ * @param g
+ */
+ @Override
+ protected void outlineShape(Graphics g) {
+ super.outlineShape(g);
+ drawCommonbendpoints(g);
+ }
+
+ /**
+ * Resets the style of this figure to its default implementation
+ */
+ public void resetStyle() {
+
+ }
+
+ /**
+ *
+ * @return
+ * the common bendpoints to draw (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=424099)
+ */
+ @SuppressWarnings("unchecked")
+ public Collection<Point> getCommonBendpointsToDraw() {
+ final Collection<Point> commonBendpointsToDraw = new HashSet<Point>();
+ final PointList bendPoints = getPoints();
+
+ final Map<?, ?> visualPartMap = getVisualPartMap(this);
+ if (visualPartMap != null) {
+ final EditPart currentEditPart = (EditPart) visualPartMap.get(this);
+ // 1. find the uml eClass of the current link
+ EClass eClass = null;
+ if (currentEditPart instanceof IGraphicalEditPart) {
+ final EObject el = ((IGraphicalEditPart) currentEditPart).resolveSemanticElement();
+ if (el != null) {
+ eClass = el.eClass();
+ }
+ }
+
+ // 2. find all connections editpart with same source AND/OR same target than the current one
+ if (currentEditPart instanceof ConnectionEditPart && eClass != null) {
+ final EditPart sourceEP = ((ConnectionEditPart) currentEditPart).getSource();
+ final EditPart targetEP = ((ConnectionEditPart) currentEditPart).getTarget();
+ final Set<Object> allConnectionsEP = new HashSet<Object>();
+ // 2.1. get all potential editpart connections
+ if (sourceEP instanceof AbstractGraphicalEditPart && targetEP instanceof AbstractGraphicalEditPart) {
+ allConnectionsEP.addAll(((AbstractGraphicalEditPart) sourceEP).getSourceConnections());
+ allConnectionsEP.addAll(((AbstractGraphicalEditPart) targetEP).getSourceConnections());
+ allConnectionsEP.addAll(((AbstractGraphicalEditPart) sourceEP).getTargetConnections());
+ allConnectionsEP.addAll(((AbstractGraphicalEditPart) targetEP).getTargetConnections());
+ allConnectionsEP.remove(currentEditPart);
+ }
+
+ // 2.2 get the figure for these connections and keep only figure when its editpart has the same kind than the current one
+ final Set<Connection> allConnections = new HashSet<Connection>();
+ if (allConnectionsEP.size() > 0) {
+ for (final Object current : allConnectionsEP) {
+ // the editpart be instance of the same class
+ if (current.getClass().isInstance(currentEditPart) && currentEditPart.getClass().isInstance(current) && current instanceof IGraphicalEditPart) {
+ final EObject resolvedElement = ((IGraphicalEditPart) current).resolveSemanticElement();
+ if (resolvedElement != null && eClass != null && resolvedElement.eClass() != eClass) {
+ continue;// we draw ben point only for elements which have the same eClass, when this eClass is not null
+ }
+ final IFigure currentFig = ((IGraphicalEditPart) current).getFigure();
+ if (currentFig instanceof Connection) {
+ allConnections.add((Connection) currentFig);
+ }
+ }
+ }
+ }
+
+ // 3. Create the list of the LineSeg of the current figure
+ final List<LineSeg> refs = new ArrayList<LineSeg>();
+ for (int i = 0; i < bendPoints.size() - 1; i++) {
+ LineSeg seg = new LineSeg(bendPoints.getPoint(i), bendPoints.getPoint(i + 1));
+ refs.add(seg);
+ }
+
+
+ // 4. find common segments between the current figure and each others link
+ // we need to associate each common segment to the concerned link
+ final Map<Connection, Map<LineSeg, List<LineSeg>>> segs = new HashMap<Connection, Map<LineSeg, List<LineSeg>>>();
+ for (Connection currentConn : allConnections) {
+ final PointList currentPoints = currentConn.getPoints();
+ final Map<LineSeg, List<LineSeg>> mapSegs = new HashMap<LineSeg, List<LineSeg>>();
+ segs.put(currentConn, mapSegs);
+ for (LineSeg refSeg : refs) {
+ final List<LineSeg> commonSubSegs = new ArrayList<LineSeg>();
+ mapSegs.put(refSeg, commonSubSegs);
+ for (int i = 0; i < currentPoints.size() - 1; i++) {
+ LineSeg tmp = new LineSeg(currentPoints.getPoint(i), currentPoints.getPoint(i + 1));
+ PointList intersection = getCommonSegment(refSeg, tmp);
+ if (intersection.size() == 2) {
+ if (!intersection.getFirstPoint().equals(intersection.getLastPoint())) {
+ double distanceFromFirst = refSeg.getOrigin().getDistance(intersection.getFirstPoint());
+ double distanceFromSecond = refSeg.getOrigin().getDistance(intersection.getLastPoint());
+ final LineSeg commonSeg;
+ // we arrange the 2 points in order to have the first point nearest of the start of the current segment
+ if (distanceFromFirst < distanceFromSecond) {
+ commonSeg = new LineSeg(intersection.getFirstPoint(), intersection.getLastPoint());
+ } else {
+ commonSeg = new LineSeg(intersection.getLastPoint(), intersection.getFirstPoint());
+ }
+ commonSubSegs.add(commonSeg);
+ }
+ }
+ }
+ }
+ }
+
+ // 5. we look for the bendpoints crossing existing link on the model, then crossing their common segment with the current figure, to find bendpoints to draw
+ for (Entry<Connection, Map<LineSeg, List<LineSeg>>> entry : segs.entrySet()) {
+ final Map<LineSeg, List<LineSeg>> commonSegMap = entry.getValue();
+ for (int i = 0; i < refs.size(); i++) { // we iterate on the segments of the current figure
+
+
+ // 5.1 find required values to find bendpoints to draw
+ final LineSeg currentFigureSeg = refs.get(i);
+ // final List<LineSeg> currentCommonSegs = segs.get(currentFigureSeg);
+ final List<LineSeg> currentCommonSegs = commonSegMap.get(currentFigureSeg);
+
+ final LineSeg previousSeg;
+ final List<LineSeg> previousCommonSegs;
+
+ final LineSeg nextSeg;
+ final List<LineSeg> nextCommonSegs;
+
+ // obtain previous segs of the current figure
+ if (i != 0) {
+ previousSeg = refs.get(i - 1);
+ previousCommonSegs = commonSegMap.get(previousSeg);
+ } else {
+ previousSeg = null;
+ previousCommonSegs = null;
+ }
+
+ // obtain next segs of the current figure
+ if (i != refs.size() - 1) {
+ nextSeg = refs.get(i + 1);
+ nextCommonSegs = commonSegMap.get(nextSeg);
+ } else {
+ nextSeg = null;
+ nextCommonSegs = null;
+ }
+
+
+ LineSeg previousCommonSeg = null;
+ LineSeg nextCommonSeg = null;
+
+ // we iterate on the common subsegment shared with others link with the current figure
+ for (int a = 0; a < currentCommonSegs.size(); a++) {
+ final LineSeg curr = currentCommonSegs.get(a);
+ final Point first = curr.getOrigin();
+ final Point second = curr.getTerminus();
+ // obtain previous common seg
+ if (a == 0) {
+ if (previousCommonSegs != null && previousCommonSegs.size() > 0) {
+ previousCommonSeg = previousCommonSegs.get(previousCommonSegs.size() - 1);
+ } else {
+ previousCommonSeg = null;
+ }
+ } else {
+ previousCommonSeg = currentCommonSegs.get(a - 1);
+ }
+
+ // obtain next common seg
+ if (a == currentCommonSegs.size() - 1) {
+ if (nextCommonSegs != null && nextCommonSegs.size() > 0) {
+ nextCommonSeg = nextCommonSegs.get(0);
+ } else {
+ nextCommonSeg = null;
+ }
+ } else {
+ nextCommonSeg = currentCommonSegs.get(a + 1);
+ }
+
+ // 5.2 calculates bendpoints visibility
+
+ // determining if we draw first point :
+ if (previousCommonSeg == null) {
+ if (i == 0) {// first segment of the figure
+ if (!bendPoints.getFirstPoint().equals(first)) {
+ // we draw the point when it is not the first anchor of the figure
+ commonBendpointsToDraw.add(first);
+ }
+ } else {
+ commonBendpointsToDraw.add(first);
+ }
+ } else if (!previousCommonSeg.getTerminus().equals(first)) {
+ // the previous common seg doesn't share this point with the current segment
+ // we draw the first point
+ commonBendpointsToDraw.add(first);
+ }
+
+ // determining if we draw the second point
+ if (nextCommonSeg == null) {
+ if (i == refs.size() - 1) {
+ if (!bendPoints.getLastPoint().equals(second)) {
+ // we draw the point when it is not the first anchor of the figure
+ commonBendpointsToDraw.add(second);
+ }
+ } else {
+ commonBendpointsToDraw.add(second);
+ }
+ } else if (!nextCommonSeg.getOrigin().equals(second)) {
+ // the next common seg doesn't share this point with the current segment
+ // we draw the second point
+ commonBendpointsToDraw.add(second);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return commonBendpointsToDraw;
+ }
+
+ /**
+ *
+ * @param g
+ * graphics
+ * @param pointsToDraw
+ * the list of the points to draw
+ */
+ public void drawCommonBendpoints(final Graphics g, final Collection<Point> bendPoints) {
+ final int diameter = getBendPointDiameter();
+ if (getDrawBendpointPreferenceValue() && bendPoints.size() > 0 && diameter > 1) {
+ // initialize the graphics
+ if (getBackgroundColor() != null) {
+ g.setForegroundColor(getBackgroundColor());
+ }
+ if (getForegroundColor() != null) {
+ g.setBackgroundColor(getForegroundColor());
+ }
+
+ for (final Point point : bendPoints) {
+ g.fillOval(point.x - (diameter - 1) / 2, point.y - (diameter - 1) / 2, diameter, diameter);
+ }
+
+ // reset the graphics
+ if (getBackgroundColor() != null) {
+ g.setBackgroundColor(getBackgroundColor());
+ }
+ if (getForegroundColor() != null) {
+ g.setForegroundColor(getForegroundColor());
+ }
+ }
+ }
+
+
+
+ /**
+ *
+ * @param g
+ *
+ */
+ protected void drawCommonbendpoints(final Graphics g) {
+ if (getPoints().size() > 2 && getDrawBendpointPreferenceValue()) {
+ final Collection<Point> commonPoints = getCommonBendpointsToDraw();
+ drawCommonBendpoints(g, commonPoints);
+ }
+ }
+
+
+
+ /**
+ *
+ * @return
+ * <code>true</code> according to the preference store
+ */
+ protected boolean getDrawBendpointPreferenceValue() {
+ return false;
+ }
+
+ /**
+ *
+ * @param figure
+ * a figure
+ * @return
+ * the visual part map for this figure or <code>null</code> if not found
+ */
+ protected Map<?, ?> getVisualPartMap(final IFigure figure) {
+ IEditorPart part = EditorHelper.getCurrentEditor();
+ if (part instanceof CoreMultiDiagramEditor) {
+ final List<IEditorPart> visibleEditors = ((CoreMultiDiagramEditor) part).getISashWindowsContainer().getVisibleIEditorParts();
+ for (final IEditorPart current : visibleEditors) {
+ final GraphicalViewer viewer = (GraphicalViewer) current.getAdapter(GraphicalViewer.class);
+ final Map<?, ?> visualPartMap = viewer.getVisualPartMap();
+ if (visualPartMap.containsKey(figure)) {
+ return visualPartMap;
+ }
+ }
+ } else {
+ // used when papyrus has been "unsashified"
+ final IWorkbench workbench = PlatformUI.getWorkbench();
+ if (workbench != null) {
+ final IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
+ if (window != null) {
+ final List<?> editors = EditorService.getInstance().getRegisteredEditorParts();
+ for (Iterator<?> j = editors.iterator(); j.hasNext();) {
+ final IEditorPart editor = (IEditorPart) j.next();
+ if (editor.getEditorSite().getWorkbenchWindow() == window) {
+ if (editor instanceof IDiagramWorkbenchPart) {
+ final IDiagramWorkbenchPart de = (IDiagramWorkbenchPart) editor;
+ final GraphicalViewer viewer = de.getDiagramGraphicalViewer();
+ final Map<?, ?> visualPartMap = viewer.getVisualPartMap();
+ if (visualPartMap.containsKey(figure)) {
+ return visualPartMap;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param seg1
+ * the first segment
+ * @param seg2
+ * the secong segment
+ * @return
+ */
+ public static final PointList getCommonSegment(final LineSeg seg1, final LineSeg seg2) {
+ final List<Point> list = new ArrayList<Point>();
+ list.add(seg1.getOrigin());
+ list.add(seg2.getOrigin());
+ list.add(seg1.getTerminus());
+ list.add(seg2.getTerminus());
+
+ List<Point> commonPoints = new ArrayList<Point>();
+ for (Point point : list) {
+ if (!commonPoints.contains(point)) {
+ if (seg1.containsPoint(point, 0) && seg2.containsPoint(point, 0)) {
+ commonPoints.add(point);
+ }
+ }
+ }
+
+ final PointList result = new PointList();
+ for (final Point point : commonPoints) {
+ result.addPoint(point);
+ }
+ return result;
+ }
+
+ /**
+ * Calculate the best diameter and set the diameter value
+ *
+ * @param diameter
+ * the diameter of the bendpoints (if diameter<=1, we set the diameter to 0)
+ */
+ public void setBendPointDiameter(final int diameter) {
+ if (diameter <= 1) {
+ this.bendpointDiameter = 0;
+ }
+ if (diameter % 2 != 0) {
+ this.bendpointDiameter = diameter;
+ } else {
+ setBendPointDiameter(diameter + 1);
+ }
+ }
+
+ /**
+ *
+ * @return
+ * the bendpoint diameter
+ */
+ protected final int getBendPointDiameter() {
+ return this.bendpointDiameter;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ICustomNodePlate.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ICustomNodePlate.java
index 27ca25137f8..e5b11c11ab3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ICustomNodePlate.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ICustomNodePlate.java
@@ -1,38 +1,38 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-
-/**
- * this class is used to raise that the implemented Default Node plate is custom.
- * So the SVGNodePlate must delegate to it some functions
- *
- */
-public interface ICustomNodePlate {
- /**
- * set the SVG node plate that contain this custom node plate
- *
- * @param svgNodePlateFigure
- * not null
- */
- public void setSVGNodePlateContainer(SVGNodePlateFigure svgNodePlateFigure);
-
- /**
- * get the SVG node plate that contains this custom node plate
- *
- * @return the SVG node plate
- */
- public SVGNodePlateFigure getSvgNodePlateContainer();
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+
+/**
+ * this class is used to raise that the implemented Default Node plate is custom.
+ * So the SVGNodePlate must delegate to it some functions
+ *
+ */
+public interface ICustomNodePlate {
+ /**
+ * set the SVG node plate that contain this custom node plate
+ *
+ * @param svgNodePlateFigure
+ * not null
+ */
+ public void setSVGNodePlateContainer(SVGNodePlateFigure svgNodePlateFigure);
+
+ /**
+ * get the SVG node plate that contains this custom node plate
+ *
+ * @return the SVG node plate
+ */
+ public SVGNodePlateFigure getSvgNodePlateContainer();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/IPapyrusNodeFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/IPapyrusNodeFigure.java
index c39e8eb023d..f430c766ebf 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/IPapyrusNodeFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/IPapyrusNodeFigure.java
@@ -1,118 +1,118 @@
-/*****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
-import org.eclipse.swt.graphics.Color;
-
-/**
- * Figure associated to {@link NodeEditPart}
- */
-// TODO: Move to infra.gmfdiag.common
-public interface IPapyrusNodeFigure extends IFigure {
-
- /**
- * get the color of the border
- *
- * @return the color
- */
- public Color getBorderColor();
-
- /**
- *
- * @return true is the figure is in the mode shadow
- */
- // @unused
- public boolean isShadow();
-
- /**
- * set the color for the border
- *
- * @param borderColor
- * color
- */
- // @unused
- public void setBorderColor(Color borderColor);
-
- /**
- * set the shadow
- *
- * @param shadow
- * a boolean true if we want to display the shadow
- */
- public void setShadow(boolean shadow);
-
- /**
- * Comes from GMF
- * <p>
- * Returns the primary shape being the View of this edit part.
- * </p>
- * <b>Warning</b> It should never return <code>null</code>
- *
- * @return the primary shape associated to this edit part.
- */
- public void setTransparency(int transparency);
-
- /**
- * Comes from GMF Sets values defining gradient data.
- *
- * @param gradientColor1
- * @param gradientColor2
- * @param gradientStyle
- * @since 1.2
- */
- public void setGradientData(int gradientColor1, int gradientColor2, int gradientStyle);
-
- /**
- * Comes from GMF Sets the value of isUsingGradient
- *
- * @param b
- * value for isUsingGradient
- * @since 1.2
- */
- public void setIsUsingGradient(boolean b);
-
- /**
- * Comes from GMF {@link NodeFigure#setLineStyle}
- *
- * @param s
- * the new line style
- * @since 1.2
- */
- public void setLineStyle(int s);
-
- /**
- * Comes from GMF {@link NodeFigure#getLineStyle}
- *
- * @since 1.2
- */
- public int getLineStyle();
-
- /**
- * Comes from GMF {@link NodeFigure#setLineWidth}
- *
- * @param w
- * the new width
- * @since 1.2
- */
- public void setLineWidth(int w);
-
- /**
- * Comes from GMF {@link NodeFigure#getLineWidth}
- *
- * @since 1.2
- */
- public int getLineWidth();
-}
+/*****************************************************************************
+ * Copyright (c) 2009 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Figure associated to {@link NodeEditPart}
+ */
+// TODO: Move to infra.gmfdiag.common
+public interface IPapyrusNodeFigure extends IFigure {
+
+ /**
+ * get the color of the border
+ *
+ * @return the color
+ */
+ public Color getBorderColor();
+
+ /**
+ *
+ * @return true is the figure is in the mode shadow
+ */
+ // @unused
+ public boolean isShadow();
+
+ /**
+ * set the color for the border
+ *
+ * @param borderColor
+ * color
+ */
+ // @unused
+ public void setBorderColor(Color borderColor);
+
+ /**
+ * set the shadow
+ *
+ * @param shadow
+ * a boolean true if we want to display the shadow
+ */
+ public void setShadow(boolean shadow);
+
+ /**
+ * Comes from GMF
+ * <p>
+ * Returns the primary shape being the View of this edit part.
+ * </p>
+ * <b>Warning</b> It should never return <code>null</code>
+ *
+ * @return the primary shape associated to this edit part.
+ */
+ public void setTransparency(int transparency);
+
+ /**
+ * Comes from GMF Sets values defining gradient data.
+ *
+ * @param gradientColor1
+ * @param gradientColor2
+ * @param gradientStyle
+ * @since 1.2
+ */
+ public void setGradientData(int gradientColor1, int gradientColor2, int gradientStyle);
+
+ /**
+ * Comes from GMF Sets the value of isUsingGradient
+ *
+ * @param b
+ * value for isUsingGradient
+ * @since 1.2
+ */
+ public void setIsUsingGradient(boolean b);
+
+ /**
+ * Comes from GMF {@link NodeFigure#setLineStyle}
+ *
+ * @param s
+ * the new line style
+ * @since 1.2
+ */
+ public void setLineStyle(int s);
+
+ /**
+ * Comes from GMF {@link NodeFigure#getLineStyle}
+ *
+ * @since 1.2
+ */
+ public int getLineStyle();
+
+ /**
+ * Comes from GMF {@link NodeFigure#setLineWidth}
+ *
+ * @param w
+ * the new width
+ * @since 1.2
+ */
+ public void setLineWidth(int w);
+
+ /**
+ * Comes from GMF {@link NodeFigure#getLineWidth}
+ *
+ * @since 1.2
+ */
+ public int getLineWidth();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusAnchorableWrappingLabel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusAnchorableWrappingLabel.java
index 72bdee4479d..2c8df9ac710 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusAnchorableWrappingLabel.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusAnchorableWrappingLabel.java
@@ -1,202 +1,202 @@
-/*****************************************************************************
- * Copyright (c) 2010 Atos Origin.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- * Arthur Daussy - arthur.daussy@atos.net - 395920: [Block Diagram Definition] All element contained by a block should be able to be linked to constraint or comment
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-import java.util.Hashtable;
-import java.util.Iterator;
-
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure;
-import org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor;
-
-/**
- * Create a papyrus wrapping label that can be targeted by a connection.
- *
- * @author arthur daussy
- *
- */
-public class PapyrusAnchorableWrappingLabel extends PapyrusWrappingLabel implements IAnchorableFigure {
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#createDefaultAnchor()
- */
- protected ConnectionAnchor createDefaultAnchor() {
- return new SlidableAnchor(this);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#szAnchor()
- */
- static public final String szAnchor = ""; //$NON-NLS-1$
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchor()
- */
- @Override
- public ConnectionAnchor getConnectionAnchor(String terminal) {
-
- ConnectionAnchor connectAnchor = (ConnectionAnchor) getConnectionAnchors().get(terminal);
- if (connectAnchor == null) {
- if (terminal.equals(szAnchor)) {
- // get a new one - this figure doesn't support static anchors
- connectAnchor = createDefaultAnchor();
- getConnectionAnchors().put(terminal, connectAnchor);
- } else {
- connectAnchor = createAnchor(BaseSlidableAnchor.parseTerminalString(terminal));
- }
- }
-
- return connectAnchor;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#createAnchor()
- */
- protected ConnectionAnchor createAnchor(PrecisionPoint p) {
- if (p == null) {
- // If the old terminal for the connection anchor cannot be resolved (by SlidableAnchor) a null
- // PrecisionPoint will passed in - this is handled here
- return createDefaultAnchor();
- }
- return new SlidableAnchor(this, p);
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchors()
- */
- protected Hashtable getConnectionAnchors() {
- if (connectionAnchors == null) {
- connectionAnchors = new Hashtable(1);
- }
- return connectionAnchors;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#connectionAnchors()
- */
- private Hashtable connectionAnchors;
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchorTerminal()
- */
- @Override
- public String getConnectionAnchorTerminal(ConnectionAnchor c) {
- if (c instanceof SlidableAnchor) {
- return ((SlidableAnchor) c).getTerminal();
- }
- if (getConnectionAnchors().containsValue(c)) {
- Iterator iter = getConnectionAnchors().keySet().iterator();
- String key;
- while (iter.hasNext()) {
- key = (String) iter.next();
- if (getConnectionAnchors().get(key).equals(c)) {
- return key;
- }
- }
- }
- getConnectionAnchor(szAnchor);
- return szAnchor;
- }
-
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getSourceConnectionAnchorAt()
- */
- @Override
- public ConnectionAnchor getSourceConnectionAnchorAt(Point p) {
- return createConnectionAnchor(p);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getTargetConnectionAnchorAt()
- */
- @Override
- public ConnectionAnchor getTargetConnectionAnchorAt(Point p) {
- return createConnectionAnchor(p);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#createConnectionAnchor()
- */
- protected ConnectionAnchor createConnectionAnchor(Point p) {
- if (p == null) {
- return getConnectionAnchor(szAnchor);
- } else {
- Point temp = p.getCopy();
- translateToRelative(temp);
- PrecisionPoint pt = BaseSlidableAnchor.getAnchorRelativeLocation(temp, getBounds());
- if (isDefaultAnchorArea(pt)) {
- return getConnectionAnchor(szAnchor);
- }
- return createAnchor(pt);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#isDefaultAnchorArea()
- */
- protected boolean isDefaultAnchorArea(PrecisionPoint p) {
- return p.preciseX >= getSlidableAnchorArea() / 2 && p.preciseX <= 1 - getSlidableAnchorArea() / 2 && p.preciseY >= getSlidableAnchorArea() / 2 && p.preciseY <= 1 - getSlidableAnchorArea() / 2;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
- * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getSlidableAnchorArea()
- */
- protected double getSlidableAnchorArea() {
- return 0.5;
- }
-
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ * Arthur Daussy - arthur.daussy@atos.net - 395920: [Block Diagram Definition] All element contained by a block should be able to be linked to constraint or comment
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import java.util.Hashtable;
+import java.util.Iterator;
+
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.BaseSlidableAnchor;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure;
+import org.eclipse.gmf.runtime.gef.ui.figures.SlidableAnchor;
+
+/**
+ * Create a papyrus wrapping label that can be targeted by a connection.
+ *
+ * @author arthur daussy
+ *
+ */
+public class PapyrusAnchorableWrappingLabel extends PapyrusWrappingLabel implements IAnchorableFigure {
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#createDefaultAnchor()
+ */
+ protected ConnectionAnchor createDefaultAnchor() {
+ return new SlidableAnchor(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#szAnchor()
+ */
+ static public final String szAnchor = ""; //$NON-NLS-1$
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchor()
+ */
+ @Override
+ public ConnectionAnchor getConnectionAnchor(String terminal) {
+
+ ConnectionAnchor connectAnchor = (ConnectionAnchor) getConnectionAnchors().get(terminal);
+ if (connectAnchor == null) {
+ if (terminal.equals(szAnchor)) {
+ // get a new one - this figure doesn't support static anchors
+ connectAnchor = createDefaultAnchor();
+ getConnectionAnchors().put(terminal, connectAnchor);
+ } else {
+ connectAnchor = createAnchor(BaseSlidableAnchor.parseTerminalString(terminal));
+ }
+ }
+
+ return connectAnchor;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#createAnchor()
+ */
+ protected ConnectionAnchor createAnchor(PrecisionPoint p) {
+ if (p == null) {
+ // If the old terminal for the connection anchor cannot be resolved (by SlidableAnchor) a null
+ // PrecisionPoint will passed in - this is handled here
+ return createDefaultAnchor();
+ }
+ return new SlidableAnchor(this, p);
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchors()
+ */
+ protected Hashtable getConnectionAnchors() {
+ if (connectionAnchors == null) {
+ connectionAnchors = new Hashtable(1);
+ }
+ return connectionAnchors;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#connectionAnchors()
+ */
+ private Hashtable connectionAnchors;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getConnectionAnchorTerminal()
+ */
+ @Override
+ public String getConnectionAnchorTerminal(ConnectionAnchor c) {
+ if (c instanceof SlidableAnchor) {
+ return ((SlidableAnchor) c).getTerminal();
+ }
+ if (getConnectionAnchors().containsValue(c)) {
+ Iterator iter = getConnectionAnchors().keySet().iterator();
+ String key;
+ while (iter.hasNext()) {
+ key = (String) iter.next();
+ if (getConnectionAnchors().get(key).equals(c)) {
+ return key;
+ }
+ }
+ }
+ getConnectionAnchor(szAnchor);
+ return szAnchor;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getSourceConnectionAnchorAt()
+ */
+ @Override
+ public ConnectionAnchor getSourceConnectionAnchorAt(Point p) {
+ return createConnectionAnchor(p);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getTargetConnectionAnchorAt()
+ */
+ @Override
+ public ConnectionAnchor getTargetConnectionAnchorAt(Point p) {
+ return createConnectionAnchor(p);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#createConnectionAnchor()
+ */
+ protected ConnectionAnchor createConnectionAnchor(Point p) {
+ if (p == null) {
+ return getConnectionAnchor(szAnchor);
+ } else {
+ Point temp = p.getCopy();
+ translateToRelative(temp);
+ PrecisionPoint pt = BaseSlidableAnchor.getAnchorRelativeLocation(temp, getBounds());
+ if (isDefaultAnchorArea(pt)) {
+ return getConnectionAnchor(szAnchor);
+ }
+ return createAnchor(pt);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#isDefaultAnchorArea()
+ */
+ protected boolean isDefaultAnchorArea(PrecisionPoint p) {
+ return p.preciseX >= getSlidableAnchorArea() / 2 && p.preciseX <= 1 - getSlidableAnchorArea() / 2 && p.preciseY >= getSlidableAnchorArea() / 2 && p.preciseY <= 1 - getSlidableAnchorArea() / 2;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gmf.runtime.draw2d.ui.figures.IAnchorableFigure#getConnectionAnchor(java.lang.String)
+ * Copied from @see org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure#getSlidableAnchorArea()
+ */
+ protected double getSlidableAnchorArea() {
+ return 0.5;
+ }
+
} \ No newline at end of file
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java
index f7eb0c705a6..d988eb6f44c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/PapyrusWrappingLabel.java
@@ -1,121 +1,121 @@
-/*****************************************************************************
- * Copyright (c) 2010 Atos Origin.
- *
- *
- * 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:
- * Atos Origin - Initial API and implementation
- * Arthur Daussy - Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements.
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 440230 - Margin Label
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-import org.eclipse.draw2d.MarginBorder;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
-import org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * This correct the bug where invisible label can be selected
- *
- * @author arthur daussy
- */
-public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrappingLabel{
-
- /**
- * Constructor.
- *
- * @param image
- */
- public PapyrusWrappingLabel(Image image) {
- super(image);
- }
-
- /**
- * Constructor.
- *
- * @param text
- */
- public PapyrusWrappingLabel(String text) {
- super(text);
- }
-
- /**
- * Constructor.
- *
- */
- public PapyrusWrappingLabel() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param text
- * @param image
- */
- public PapyrusWrappingLabel(String text, Image image) {
- super(text, image);
- }
-
- /**
- * Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements.
- * On this bug bug come from that invisible label return true containsPoint(int, int) even if there invisible
- *
- * This is a temporary fix until the real issue described in Bug 363362
- * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=363362) is fixed by GMF.
- *
- * @see org.eclipse.draw2d.Figure#containsPoint(int, int)
- *
- * @param x
- * @param y
- * @return
- */
- @Override
- public boolean containsPoint(int x, int y) {
- if (isVisible()) {
- return super.containsPoint(x, y);
- }
- return false;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel#setMarginLabel(int, int)
- *
- * @param xMargin Vertical margin
- * @param yMargin Horizontal margin
- */
- @Override
- public void setMarginLabel(int xMargin, int yMargin) {
-
- this.setMarginLabel(xMargin, yMargin , xMargin, yMargin);
-
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel#setMarginLabel(int, int, int, int)
- *
- * @param leftMargin
- * @param topMargin
- * @param rightMargin
- * @param bottomMargin
- */
- @Override
- public void setMarginLabel(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
- MarginBorder mb = new MarginBorder(topMargin, leftMargin, bottomMargin, rightMargin);
- this.setBorder(mb);
- repaint();
- revalidate();
-
- }
-
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2010 Atos Origin.
+ *
+ *
+ * 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:
+ * Atos Origin - Initial API and implementation
+ * Arthur Daussy - Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements.
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 440230 - Margin Label
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import org.eclipse.draw2d.MarginBorder;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.WrappingLabel;
+import org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * This correct the bug where invisible label can be selected
+ *
+ * @author arthur daussy
+ */
+public class PapyrusWrappingLabel extends WrappingLabel implements IPapyrusWrappingLabel{
+
+ /**
+ * Constructor.
+ *
+ * @param image
+ */
+ public PapyrusWrappingLabel(Image image) {
+ super(image);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param text
+ */
+ public PapyrusWrappingLabel(String text) {
+ super(text);
+ }
+
+ /**
+ * Constructor.
+ *
+ */
+ public PapyrusWrappingLabel() {
+ super();
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param text
+ * @param image
+ */
+ public PapyrusWrappingLabel(String text, Image image) {
+ super(text, image);
+ }
+
+ /**
+ * Bug 354622 - [ActivityDiagram] Object Flows selection prevent selecting other close elements.
+ * On this bug bug come from that invisible label return true containsPoint(int, int) even if there invisible
+ *
+ * This is a temporary fix until the real issue described in Bug 363362
+ * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=363362) is fixed by GMF.
+ *
+ * @see org.eclipse.draw2d.Figure#containsPoint(int, int)
+ *
+ * @param x
+ * @param y
+ * @return
+ */
+ @Override
+ public boolean containsPoint(int x, int y) {
+ if (isVisible()) {
+ return super.containsPoint(x, y);
+ }
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel#setMarginLabel(int, int)
+ *
+ * @param xMargin Vertical margin
+ * @param yMargin Horizontal margin
+ */
+ @Override
+ public void setMarginLabel(int xMargin, int yMargin) {
+
+ this.setMarginLabel(xMargin, yMargin , xMargin, yMargin);
+
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.figure.IPapyrusWrappingLabel#setMarginLabel(int, int, int, int)
+ *
+ * @param leftMargin
+ * @param topMargin
+ * @param rightMargin
+ * @param bottomMargin
+ */
+ @Override
+ public void setMarginLabel(int leftMargin, int topMargin, int rightMargin, int bottomMargin) {
+ MarginBorder mb = new MarginBorder(topMargin, leftMargin, bottomMargin, rightMargin);
+ this.setBorder(mb);
+ repaint();
+ revalidate();
+
+ }
+
+
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ScalableCompartmentFigure.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ScalableCompartmentFigure.java
index 255970e0655..1a35c457bfe 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ScalableCompartmentFigure.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ScalableCompartmentFigure.java
@@ -1,37 +1,37 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
-import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
-
-/**
- * Specific figure for the compartment
- */
-public class ScalableCompartmentFigure extends ResizableCompartmentFigure {
-
- /**
- * Creates a new Compartment figure.
- *
- * @param compartmentTitle
- * title of the compartment
- * @param mm
- * the <code>IMapMode</code> that is used to initialize the
- * default values of of the scrollpane contained inside the figure. This is
- * necessary since the figure is not attached at construction time and consequently
- * can't get access to the owned IMapMode in the parent containment hierarchy.
- */
- public ScalableCompartmentFigure(String compartmentTitle, IMapMode mm) {
- super(compartmentTitle, mm);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ /*****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.IMapMode;
+
+/**
+ * Specific figure for the compartment
+ */
+public class ScalableCompartmentFigure extends ResizableCompartmentFigure {
+
+ /**
+ * Creates a new Compartment figure.
+ *
+ * @param compartmentTitle
+ * title of the compartment
+ * @param mm
+ * the <code>IMapMode</code> that is used to initialize the
+ * default values of of the scrollpane contained inside the figure. This is
+ * necessary since the figure is not attached at construction time and consequently
+ * can't get access to the owned IMapMode in the parent containment hierarchy.
+ */
+ public ScalableCompartmentFigure(String compartmentTitle, IMapMode mm) {
+ super(compartmentTitle, mm);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ShapeFlowLayout.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ShapeFlowLayout.java
index 09fdf294975..0707fa6d743 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ShapeFlowLayout.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/ShapeFlowLayout.java
@@ -1,327 +1,327 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-import java.util.Iterator;
-
-import org.eclipse.draw2d.FlowLayout;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Rectangle;
-
-/**
- * Flow Layout customized for the shapes figure (to be sure they get the maximum size and they are centered.
- */
-public class ShapeFlowLayout extends FlowLayout {
-
- /**
- * Creates a new ShapeFlowLayout, by default horizontal.
- */
- public ShapeFlowLayout() {
- super(true);
- setStretchMinorAxis(true);
- setMajorAlignment(ALIGN_CENTER);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void layout(IFigure parent) {
- data = new WorkingData() {
- };
- Rectangle relativeArea = parent.getClientArea();
- data.area = transposer.t(relativeArea);
- Iterator iterator = parent.getChildren().iterator();
- int totalPrefWidth = 0;
- int maxPrefHeight = 0;
- int dx;
- // Calculate the hints to be passed to children
- int wHint = -1;
- int hHint = -1;
- wHint = parent.getClientArea().width;
- hHint = parent.getClientArea().height;
- initVariables(parent);
- initRow();
- // compute max height and sum of width
- while (iterator.hasNext()) {
- IFigure f = (IFigure) iterator.next();
- Dimension pref = transposer.t(getChildSize(f, wHint, hHint));
- totalPrefWidth += pref.width;
- maxPrefHeight = Math.max(maxPrefHeight, pref.height);
- }
- // compute ratio to get the max width (i.e. the multiplier to be sure that figures would take all the width of the compartment
- double ratioWidth = 1;
- if (totalPrefWidth > 0) {
- ratioWidth = wHint / totalPrefWidth;
- }
- // compute the ration so the heighest figure would fit the height of the compartment
- double ratioHeight = 1;
- if (maxPrefHeight > 0) {
- ratioHeight = hHint / maxPrefHeight;
- }
- // get the smallest ratio => multiplier to get all the maximum size of the figure
- double ratio = Math.min(ratioHeight, ratioWidth);
- // reset iterator and run computation
- iterator = parent.getChildren().iterator();
- while (iterator.hasNext()) {
- IFigure f = (IFigure) iterator.next();
- Dimension pref = transposer.t(getChildSize(f, wHint, hHint));
- // scale using the ratio
- Rectangle r = new Rectangle(0, 0, (int) (pref.width * ratio), (int) (pref.height * ratio));
- if (data.rowCount > 0) {
- if (data.rowWidth + pref.width > data.maxWidth) {
- layoutRow(parent);
- }
- }
- r.x = data.rowX;
- r.y = data.rowY;
- dx = r.width + getMinorSpacing();
- data.rowX += dx;
- data.rowWidth += dx;
- data.rowHeight = Math.max(data.rowHeight, r.height);
- data.row[data.rowCount] = f;
- data.bounds[data.rowCount] = r;
- data.rowCount++;
- }
- if (data.rowCount != 0) {
- layoutRow(parent);
- }
- data = null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void layoutRow(IFigure parent) {
- int majorAdjustment = 0;
- int minorAdjustment = 0;
- int correctMajorAlignment = getMajorAlignment();
- int correctMinorAlignment = getMinorAlignment();
- majorAdjustment = data.area.width - data.rowWidth + getMinorSpacing();
- switch (correctMajorAlignment) {
- case ALIGN_TOPLEFT:
- majorAdjustment = 0;
- break;
- case ALIGN_CENTER:
- majorAdjustment /= 2;
- break;
- case ALIGN_BOTTOMRIGHT:
- break;
- }
- for (int j = 0; j < data.rowCount; j++) {
- if (isStretchMinorAxis()) {
- data.bounds[j].height = data.rowHeight;
- } else {
- minorAdjustment = data.rowHeight - data.bounds[j].height;
- switch (correctMinorAlignment) {
- case ALIGN_TOPLEFT:
- minorAdjustment = 0;
- break;
- case ALIGN_CENTER:
- minorAdjustment /= 2;
- break;
- case ALIGN_BOTTOMRIGHT:
- break;
- }
- data.bounds[j].y += minorAdjustment;
- }
- data.bounds[j].x += majorAdjustment;
- setBoundsOfChild(parent, data.row[j], transposer.t(data.bounds[j]));
- }
- data.rowY += getMajorSpacing() + data.rowHeight;
- initRow();
- }
- // /**
- // * {@inheritDoc}
- // */
- // @Override
- // public void layout(IFigure parent) {
- // if(!parent.isVisible())
- // return;
- // List children = getChildren(parent);
- // int numChildren = children.size();
- // Rectangle clientArea = transposer.t(parent.getClientArea());
- // int x = clientArea.x;
- // int y = clientArea.y;
- // int availableHeight = clientArea.height;
- //
- // Dimension prefSizes[] = new Dimension[numChildren];
- // Dimension minSizes[] = new Dimension[numChildren];
- // Dimension maxSizes[] = new Dimension[numChildren];
- //
- // // Calculate the width and height hints. If it's a vertical ToolBarLayout,
- // // then ignore the height hint (set it to -1); otherwise, ignore the
- // // width hint. These hints will be passed to the children of the parent
- // // figure when getting their preferred size.
- // int wHint = -1;
- // int hHint = -1;
- // if(isHorizontal()) {
- // hHint = parent.getClientArea(Rectangle.SINGLETON).height;
- // } else {
- // wHint = parent.getClientArea(Rectangle.SINGLETON).width;
- // }
- //
- // /*
- // * Calculate sum of preferred heights of all children(totalHeight).
- // * Calculate sum of minimum heights of all children(minHeight).
- // * Cache Preferred Sizes and Minimum Sizes of all children.
- // *
- // * totalHeight is the sum of the preferred heights of all children
- // * totalMinHeight is the sum of the minimum heights of all children
- // * prefMinSumHeight is the sum of the difference between all children's
- // * preferred heights and minimum heights. (This is used as a ratio to
- // * calculate how much each child will shrink).
- // */
- // IFigure child;
- // int totalHeight = 0;
- // int totalMinHeight = 0;
- // double totalMaxHeight = 0;
- // int prefMinSumHeight = 0;
- // double prefMaxSumHeight = 0;
- //
- // for(int i = 0; i < numChildren; i++) {
- // child = (IFigure)children.get(i);
- //
- // prefSizes[i] = transposer.t(child.getPreferredSize(wHint, hHint));
- // minSizes[i] = transposer.t(child.getMinimumSize(wHint, hHint));
- // maxSizes[i] = transposer.t(child.getMaximumSize());
- //
- // if(getConstraint(child) != null) {
- // double ratio = ((Double)getConstraint(child)).doubleValue();
- // int prefHeight = (int)(ratio * availableHeight);
- // prefHeight = Math.max(prefHeight, minSizes[i].height);
- // prefHeight = Math.min(prefHeight, maxSizes[i].height);
- // prefSizes[i].height = prefHeight;
- // }
- //
- // totalHeight += prefSizes[i].height;
- // totalMinHeight += minSizes[i].height;
- // totalMaxHeight += maxSizes[i].height;
- // }
- // totalHeight += (numChildren - 1) * spacing;
- // totalMinHeight += (numChildren - 1) * spacing;
- // totalMaxHeight += (numChildren - 1) * spacing;
- // prefMinSumHeight = totalHeight - totalMinHeight;
- // prefMaxSumHeight = totalMaxHeight - totalHeight;
- //
- // /*
- // * The total amount that the children must be shrunk is the
- // * sum of the preferred Heights of the children minus
- // * Max(the available area and the sum of the minimum heights of the children).
- // *
- // * amntShrinkHeight is the combined amount that the children must shrink
- // * amntShrinkCurrentHeight is the amount each child will shrink respectively
- // */
- // int amntShrinkHeight = totalHeight - Math.max(availableHeight, totalMinHeight);
- //
- // for(int i = 0; i < numChildren; i++) {
- // int amntShrinkCurrentHeight = 0;
- // int prefHeight = prefSizes[i].height;
- // int minHeight = minSizes[i].height;
- // int maxHeight = maxSizes[i].height;
- // int prefWidth = prefSizes[i].width;
- // int minWidth = minSizes[i].width;
- // int maxWidth = maxSizes[i].width;
- // Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
- //
- // child = (IFigure)children.get(i);
- // if(getStretchMajorAxis()) {
- // if(amntShrinkHeight > 0 && prefMinSumHeight != 0)
- // amntShrinkCurrentHeight = (int)((long)(prefHeight - minHeight) * amntShrinkHeight / (prefMinSumHeight));
- // else if(amntShrinkHeight < 0 && totalHeight != 0)
- // amntShrinkCurrentHeight = (int)(((maxHeight - prefHeight) / prefMaxSumHeight) * amntShrinkHeight);
- // }
- //
- // if(newBounds.height - amntShrinkCurrentHeight > maxHeight)
- // amntShrinkCurrentHeight = newBounds.height - maxHeight;
- // newBounds.height -= amntShrinkCurrentHeight;
- //
- // int width = Math.min(prefWidth, maxWidth);
- // if(matchWidth)
- // width = maxWidth;
- // width = Math.max(minWidth, Math.min(clientArea.width, width));
- //
- // // compute the width by taking into account the shrink ratio
- // if(prefHeight !=0) {
- // int shrinkWidth = newBounds.height * prefWidth/prefHeight;
- // width = Math.min(width, shrinkWidth);
- // }
- //
- // newBounds.width = width;
- //
- // int adjust = clientArea.width - width;
- // switch(minorAlignment) {
- // case ALIGN_TOPLEFT:
- // adjust = 0;
- // break;
- // case ALIGN_CENTER:
- // adjust /= 2;
- // break;
- // case ALIGN_BOTTOMRIGHT:
- // break;
- // }
- // newBounds.x += adjust;
- // child.setBounds(transposer.t(newBounds));
- //
- // amntShrinkHeight -= amntShrinkCurrentHeight;
- // prefMinSumHeight -= (prefHeight - minHeight);
- // prefMaxSumHeight -= (maxHeight - prefHeight);
- // totalHeight -= prefHeight;
- // y += newBounds.height + spacing;
- // }
- // }
- // /**
- // * Calculates either the preferred or minimum children size
- // */
- // private Dimension calculateChildrenSize(
- // List children,
- // int wHint,
- // int hHint,
- // boolean preferred) {
- // Dimension childSize;
- // IFigure child;
- // int height = 0, width = 0;
- // for (int i = 0; i < children.size(); i++) {
- // child = (IFigure) children.get(i);
- // childSize =
- // transposer.t(
- // preferred
- // ? child.getPreferredSize(wHint, hHint)
- // : child.getMinimumSize(wHint, hHint));
- // height += childSize.height;
- // width = Math.max(width, childSize.width);
- // }
- // return new Dimension(width, height);
- // }
- // /**
- // * Gets the list of children after applying the layout options of
- // * ignore invisible children & reverse children
- // */
- // private List getChildren(IFigure container) {
- // List children = new ArrayList(container.getChildren());
- // if(getIgnoreInvisibleChildren()) {
- // Iterator iter = children.iterator();
- // while(iter.hasNext()) {
- // IFigure f = (IFigure)iter.next();
- // if(!f.isVisible())
- // iter.remove();
- // }
- // }
- // if(isReversed())
- // Collections.reverse(children);
- // return children;
- // }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import java.util.Iterator;
+
+import org.eclipse.draw2d.FlowLayout;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ * Flow Layout customized for the shapes figure (to be sure they get the maximum size and they are centered.
+ */
+public class ShapeFlowLayout extends FlowLayout {
+
+ /**
+ * Creates a new ShapeFlowLayout, by default horizontal.
+ */
+ public ShapeFlowLayout() {
+ super(true);
+ setStretchMinorAxis(true);
+ setMajorAlignment(ALIGN_CENTER);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void layout(IFigure parent) {
+ data = new WorkingData() {
+ };
+ Rectangle relativeArea = parent.getClientArea();
+ data.area = transposer.t(relativeArea);
+ Iterator iterator = parent.getChildren().iterator();
+ int totalPrefWidth = 0;
+ int maxPrefHeight = 0;
+ int dx;
+ // Calculate the hints to be passed to children
+ int wHint = -1;
+ int hHint = -1;
+ wHint = parent.getClientArea().width;
+ hHint = parent.getClientArea().height;
+ initVariables(parent);
+ initRow();
+ // compute max height and sum of width
+ while (iterator.hasNext()) {
+ IFigure f = (IFigure) iterator.next();
+ Dimension pref = transposer.t(getChildSize(f, wHint, hHint));
+ totalPrefWidth += pref.width;
+ maxPrefHeight = Math.max(maxPrefHeight, pref.height);
+ }
+ // compute ratio to get the max width (i.e. the multiplier to be sure that figures would take all the width of the compartment
+ double ratioWidth = 1;
+ if (totalPrefWidth > 0) {
+ ratioWidth = wHint / totalPrefWidth;
+ }
+ // compute the ration so the heighest figure would fit the height of the compartment
+ double ratioHeight = 1;
+ if (maxPrefHeight > 0) {
+ ratioHeight = hHint / maxPrefHeight;
+ }
+ // get the smallest ratio => multiplier to get all the maximum size of the figure
+ double ratio = Math.min(ratioHeight, ratioWidth);
+ // reset iterator and run computation
+ iterator = parent.getChildren().iterator();
+ while (iterator.hasNext()) {
+ IFigure f = (IFigure) iterator.next();
+ Dimension pref = transposer.t(getChildSize(f, wHint, hHint));
+ // scale using the ratio
+ Rectangle r = new Rectangle(0, 0, (int) (pref.width * ratio), (int) (pref.height * ratio));
+ if (data.rowCount > 0) {
+ if (data.rowWidth + pref.width > data.maxWidth) {
+ layoutRow(parent);
+ }
+ }
+ r.x = data.rowX;
+ r.y = data.rowY;
+ dx = r.width + getMinorSpacing();
+ data.rowX += dx;
+ data.rowWidth += dx;
+ data.rowHeight = Math.max(data.rowHeight, r.height);
+ data.row[data.rowCount] = f;
+ data.bounds[data.rowCount] = r;
+ data.rowCount++;
+ }
+ if (data.rowCount != 0) {
+ layoutRow(parent);
+ }
+ data = null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void layoutRow(IFigure parent) {
+ int majorAdjustment = 0;
+ int minorAdjustment = 0;
+ int correctMajorAlignment = getMajorAlignment();
+ int correctMinorAlignment = getMinorAlignment();
+ majorAdjustment = data.area.width - data.rowWidth + getMinorSpacing();
+ switch (correctMajorAlignment) {
+ case ALIGN_TOPLEFT:
+ majorAdjustment = 0;
+ break;
+ case ALIGN_CENTER:
+ majorAdjustment /= 2;
+ break;
+ case ALIGN_BOTTOMRIGHT:
+ break;
+ }
+ for (int j = 0; j < data.rowCount; j++) {
+ if (isStretchMinorAxis()) {
+ data.bounds[j].height = data.rowHeight;
+ } else {
+ minorAdjustment = data.rowHeight - data.bounds[j].height;
+ switch (correctMinorAlignment) {
+ case ALIGN_TOPLEFT:
+ minorAdjustment = 0;
+ break;
+ case ALIGN_CENTER:
+ minorAdjustment /= 2;
+ break;
+ case ALIGN_BOTTOMRIGHT:
+ break;
+ }
+ data.bounds[j].y += minorAdjustment;
+ }
+ data.bounds[j].x += majorAdjustment;
+ setBoundsOfChild(parent, data.row[j], transposer.t(data.bounds[j]));
+ }
+ data.rowY += getMajorSpacing() + data.rowHeight;
+ initRow();
+ }
+ // /**
+ // * {@inheritDoc}
+ // */
+ // @Override
+ // public void layout(IFigure parent) {
+ // if(!parent.isVisible())
+ // return;
+ // List children = getChildren(parent);
+ // int numChildren = children.size();
+ // Rectangle clientArea = transposer.t(parent.getClientArea());
+ // int x = clientArea.x;
+ // int y = clientArea.y;
+ // int availableHeight = clientArea.height;
+ //
+ // Dimension prefSizes[] = new Dimension[numChildren];
+ // Dimension minSizes[] = new Dimension[numChildren];
+ // Dimension maxSizes[] = new Dimension[numChildren];
+ //
+ // // Calculate the width and height hints. If it's a vertical ToolBarLayout,
+ // // then ignore the height hint (set it to -1); otherwise, ignore the
+ // // width hint. These hints will be passed to the children of the parent
+ // // figure when getting their preferred size.
+ // int wHint = -1;
+ // int hHint = -1;
+ // if(isHorizontal()) {
+ // hHint = parent.getClientArea(Rectangle.SINGLETON).height;
+ // } else {
+ // wHint = parent.getClientArea(Rectangle.SINGLETON).width;
+ // }
+ //
+ // /*
+ // * Calculate sum of preferred heights of all children(totalHeight).
+ // * Calculate sum of minimum heights of all children(minHeight).
+ // * Cache Preferred Sizes and Minimum Sizes of all children.
+ // *
+ // * totalHeight is the sum of the preferred heights of all children
+ // * totalMinHeight is the sum of the minimum heights of all children
+ // * prefMinSumHeight is the sum of the difference between all children's
+ // * preferred heights and minimum heights. (This is used as a ratio to
+ // * calculate how much each child will shrink).
+ // */
+ // IFigure child;
+ // int totalHeight = 0;
+ // int totalMinHeight = 0;
+ // double totalMaxHeight = 0;
+ // int prefMinSumHeight = 0;
+ // double prefMaxSumHeight = 0;
+ //
+ // for(int i = 0; i < numChildren; i++) {
+ // child = (IFigure)children.get(i);
+ //
+ // prefSizes[i] = transposer.t(child.getPreferredSize(wHint, hHint));
+ // minSizes[i] = transposer.t(child.getMinimumSize(wHint, hHint));
+ // maxSizes[i] = transposer.t(child.getMaximumSize());
+ //
+ // if(getConstraint(child) != null) {
+ // double ratio = ((Double)getConstraint(child)).doubleValue();
+ // int prefHeight = (int)(ratio * availableHeight);
+ // prefHeight = Math.max(prefHeight, minSizes[i].height);
+ // prefHeight = Math.min(prefHeight, maxSizes[i].height);
+ // prefSizes[i].height = prefHeight;
+ // }
+ //
+ // totalHeight += prefSizes[i].height;
+ // totalMinHeight += minSizes[i].height;
+ // totalMaxHeight += maxSizes[i].height;
+ // }
+ // totalHeight += (numChildren - 1) * spacing;
+ // totalMinHeight += (numChildren - 1) * spacing;
+ // totalMaxHeight += (numChildren - 1) * spacing;
+ // prefMinSumHeight = totalHeight - totalMinHeight;
+ // prefMaxSumHeight = totalMaxHeight - totalHeight;
+ //
+ // /*
+ // * The total amount that the children must be shrunk is the
+ // * sum of the preferred Heights of the children minus
+ // * Max(the available area and the sum of the minimum heights of the children).
+ // *
+ // * amntShrinkHeight is the combined amount that the children must shrink
+ // * amntShrinkCurrentHeight is the amount each child will shrink respectively
+ // */
+ // int amntShrinkHeight = totalHeight - Math.max(availableHeight, totalMinHeight);
+ //
+ // for(int i = 0; i < numChildren; i++) {
+ // int amntShrinkCurrentHeight = 0;
+ // int prefHeight = prefSizes[i].height;
+ // int minHeight = minSizes[i].height;
+ // int maxHeight = maxSizes[i].height;
+ // int prefWidth = prefSizes[i].width;
+ // int minWidth = minSizes[i].width;
+ // int maxWidth = maxSizes[i].width;
+ // Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
+ //
+ // child = (IFigure)children.get(i);
+ // if(getStretchMajorAxis()) {
+ // if(amntShrinkHeight > 0 && prefMinSumHeight != 0)
+ // amntShrinkCurrentHeight = (int)((long)(prefHeight - minHeight) * amntShrinkHeight / (prefMinSumHeight));
+ // else if(amntShrinkHeight < 0 && totalHeight != 0)
+ // amntShrinkCurrentHeight = (int)(((maxHeight - prefHeight) / prefMaxSumHeight) * amntShrinkHeight);
+ // }
+ //
+ // if(newBounds.height - amntShrinkCurrentHeight > maxHeight)
+ // amntShrinkCurrentHeight = newBounds.height - maxHeight;
+ // newBounds.height -= amntShrinkCurrentHeight;
+ //
+ // int width = Math.min(prefWidth, maxWidth);
+ // if(matchWidth)
+ // width = maxWidth;
+ // width = Math.max(minWidth, Math.min(clientArea.width, width));
+ //
+ // // compute the width by taking into account the shrink ratio
+ // if(prefHeight !=0) {
+ // int shrinkWidth = newBounds.height * prefWidth/prefHeight;
+ // width = Math.min(width, shrinkWidth);
+ // }
+ //
+ // newBounds.width = width;
+ //
+ // int adjust = clientArea.width - width;
+ // switch(minorAlignment) {
+ // case ALIGN_TOPLEFT:
+ // adjust = 0;
+ // break;
+ // case ALIGN_CENTER:
+ // adjust /= 2;
+ // break;
+ // case ALIGN_BOTTOMRIGHT:
+ // break;
+ // }
+ // newBounds.x += adjust;
+ // child.setBounds(transposer.t(newBounds));
+ //
+ // amntShrinkHeight -= amntShrinkCurrentHeight;
+ // prefMinSumHeight -= (prefHeight - minHeight);
+ // prefMaxSumHeight -= (maxHeight - prefHeight);
+ // totalHeight -= prefHeight;
+ // y += newBounds.height + spacing;
+ // }
+ // }
+ // /**
+ // * Calculates either the preferred or minimum children size
+ // */
+ // private Dimension calculateChildrenSize(
+ // List children,
+ // int wHint,
+ // int hHint,
+ // boolean preferred) {
+ // Dimension childSize;
+ // IFigure child;
+ // int height = 0, width = 0;
+ // for (int i = 0; i < children.size(); i++) {
+ // child = (IFigure) children.get(i);
+ // childSize =
+ // transposer.t(
+ // preferred
+ // ? child.getPreferredSize(wHint, hHint)
+ // : child.getMinimumSize(wHint, hHint));
+ // height += childSize.height;
+ // width = Math.max(width, childSize.width);
+ // }
+ // return new Dimension(width, height);
+ // }
+ // /**
+ // * Gets the list of children after applying the layout options of
+ // * ignore invisible children & reverse children
+ // */
+ // private List getChildren(IFigure container) {
+ // List children = new ArrayList(container.getChildren());
+ // if(getIgnoreInvisibleChildren()) {
+ // Iterator iter = children.iterator();
+ // while(iter.hasNext()) {
+ // IFigure f = (IFigure)iter.next();
+ // if(!f.isVisible())
+ // iter.remove();
+ // }
+ // }
+ // if(isReversed())
+ // Collections.reverse(children);
+ // return children;
+ // }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/SubCompartmentLayoutManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/SubCompartmentLayoutManager.java
index 99862746392..796b19d517b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/SubCompartmentLayoutManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/figure/node/SubCompartmentLayoutManager.java
@@ -1,110 +1,110 @@
-/****************************************************************************
- * Copyright (c) 2009 CEA LIST.
- *
- * 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:
- * Patrick Tessier (CEA LIST), Thibault Landre (Atos Origin) - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
-
-import org.eclipse.draw2d.AbstractLayout;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
-
-/**
- * this is the layout manager in charge to place element in compartment element
- */
-public class SubCompartmentLayoutManager extends AbstractLayout {
-
- protected final static int MINIMUMCOMPARTMENTSIZE = 15;
-
- protected final static int MINIMUM_COMPARTMENT_WIDTH = 20;
-
- protected int preferedHeight = MINIMUMCOMPARTMENTSIZE;
-
- @Override
- protected Dimension calculatePreferredSize(IFigure figure, int wHint, int hHint) {
- Dimension dim = new Dimension(10, preferedHeight);
- if (!figure.getChildren().isEmpty()) {
- Object compartment = figure.getChildren().get(0);
- if (compartment instanceof ResizableCompartmentFigure) {
- Dimension compartmentPreferredSize = ((ResizableCompartmentFigure) compartment).getPreferredSize();
- dim.height = compartmentPreferredSize.height + 10;
- if (dim.height == 0) {
- dim.height = 20;
- }
- dim.width = compartmentPreferredSize.width;
- }
- }
- return dim;
- }
-
- @Override
- public Dimension getMinimumSize(IFigure container, int wHint, int hHint) {
- return new Dimension(MINIMUM_COMPARTMENT_WIDTH, MINIMUMCOMPARTMENTSIZE);
- }
-
- @Override
- public void layout(IFigure container) {
- for (int i = 0; i < container.getChildren().size(); i++) {
- IFigure child = ((IFigure) container.getChildren().get(i));
- Rectangle bound = new Rectangle(child.getBounds());
- bound.setSize(getPreferedSize(child));
- bound.x = container.getBounds().x;
- bound.width = container.getBounds().width;
- if (i > 0) {
- bound.y = ((IFigure) container.getChildren().get(i - 1)).getBounds().getBottomLeft().y + 1;
- } else {
- bound.y = container.getBounds().y;
- }
- child.setBounds(bound);
- }
- // container
- int containersize = container.getChildren().size();
- if (containersize > 0) {
- IFigure lastChild = (IFigure) container.getChildren().get(containersize - 1);
- Rectangle lastRectangle = lastChild.getBounds();
- lastRectangle.height = container.getBounds().y + container.getBounds().height - lastRectangle.y;
- lastRectangle.width = container.getBounds().width;
- lastChild.setBounds(lastRectangle);
- }
- }
-
- public Dimension getPreferedSize(IFigure figure) {
- Dimension dim = new Dimension(10, preferedHeight);
- if (figure.getChildren().size() > 0) {
- if (figure.getChildren().get(0) instanceof ResizableCompartmentFigure) {
- dim.height = ((ResizableCompartmentFigure) figure.getChildren().get(0)).getPreferredSize().height + 10;
- if (dim.height == 0) {
- dim.height = 20;
- }
- }
- }
- return dim;
- }
-
- /**
- * Sets the constraint for the given figure.
- *
- * @param child
- * the child
- * @param constraint
- * the child's new constraint
- */
- @Override
- public void setConstraint(IFigure child, Object constraint) {
- if (constraint instanceof Rectangle && ((Rectangle) constraint).height > MINIMUMCOMPARTMENTSIZE) {
- preferedHeight = ((Rectangle) constraint).height;
- } else {
- preferedHeight = MINIMUMCOMPARTMENTSIZE;
- }
- invalidate(child);
- }
-}
+/****************************************************************************
+ * Copyright (c) 2009 CEA LIST.
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST), Thibault Landre (Atos Origin) - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.figure.node;
+
+import org.eclipse.draw2d.AbstractLayout;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
+
+/**
+ * this is the layout manager in charge to place element in compartment element
+ */
+public class SubCompartmentLayoutManager extends AbstractLayout {
+
+ protected final static int MINIMUMCOMPARTMENTSIZE = 15;
+
+ protected final static int MINIMUM_COMPARTMENT_WIDTH = 20;
+
+ protected int preferedHeight = MINIMUMCOMPARTMENTSIZE;
+
+ @Override
+ protected Dimension calculatePreferredSize(IFigure figure, int wHint, int hHint) {
+ Dimension dim = new Dimension(10, preferedHeight);
+ if (!figure.getChildren().isEmpty()) {
+ Object compartment = figure.getChildren().get(0);
+ if (compartment instanceof ResizableCompartmentFigure) {
+ Dimension compartmentPreferredSize = ((ResizableCompartmentFigure) compartment).getPreferredSize();
+ dim.height = compartmentPreferredSize.height + 10;
+ if (dim.height == 0) {
+ dim.height = 20;
+ }
+ dim.width = compartmentPreferredSize.width;
+ }
+ }
+ return dim;
+ }
+
+ @Override
+ public Dimension getMinimumSize(IFigure container, int wHint, int hHint) {
+ return new Dimension(MINIMUM_COMPARTMENT_WIDTH, MINIMUMCOMPARTMENTSIZE);
+ }
+
+ @Override
+ public void layout(IFigure container) {
+ for (int i = 0; i < container.getChildren().size(); i++) {
+ IFigure child = ((IFigure) container.getChildren().get(i));
+ Rectangle bound = new Rectangle(child.getBounds());
+ bound.setSize(getPreferedSize(child));
+ bound.x = container.getBounds().x;
+ bound.width = container.getBounds().width;
+ if (i > 0) {
+ bound.y = ((IFigure) container.getChildren().get(i - 1)).getBounds().getBottomLeft().y + 1;
+ } else {
+ bound.y = container.getBounds().y;
+ }
+ child.setBounds(bound);
+ }
+ // container
+ int containersize = container.getChildren().size();
+ if (containersize > 0) {
+ IFigure lastChild = (IFigure) container.getChildren().get(containersize - 1);
+ Rectangle lastRectangle = lastChild.getBounds();
+ lastRectangle.height = container.getBounds().y + container.getBounds().height - lastRectangle.y;
+ lastRectangle.width = container.getBounds().width;
+ lastChild.setBounds(lastRectangle);
+ }
+ }
+
+ public Dimension getPreferedSize(IFigure figure) {
+ Dimension dim = new Dimension(10, preferedHeight);
+ if (figure.getChildren().size() > 0) {
+ if (figure.getChildren().get(0) instanceof ResizableCompartmentFigure) {
+ dim.height = ((ResizableCompartmentFigure) figure.getChildren().get(0)).getPreferredSize().height + 10;
+ if (dim.height == 0) {
+ dim.height = 20;
+ }
+ }
+ }
+ return dim;
+ }
+
+ /**
+ * Sets the constraint for the given figure.
+ *
+ * @param child
+ * the child
+ * @param constraint
+ * the child's new constraint
+ */
+ @Override
+ public void setConstraint(IFigure child, Object constraint) {
+ if (constraint instanceof Rectangle && ((Rectangle) constraint).height > MINIMUMCOMPARTMENTSIZE) {
+ preferedHeight = ((Rectangle) constraint).height;
+ } else {
+ preferedHeight = MINIMUMCOMPARTMENTSIZE;
+ }
+ invalidate(child);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java
index ed746725dcc..5e5e8a0d70c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/RectangleUtils.java
@@ -1,67 +1,67 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.geometry;
-
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.Rectangle;
-
-/**
- *
- * Utils class for drawd2D Rectangle
- *
- */
-public class RectangleUtils {
-
- private RectangleUtils() {
- // to prevent instantiation
- }
-
-
- /**
- *
- * @param rect
- * a rectangle
- * @param segment
- * a segment
- * @return
- * the intersection point between the segment and the rectangle, if exists
- */
- public static final PrecisionPoint getIntersectionPoint(final Rectangle rect, final Segment segment) {
- PrecisionPoint result = null;
-
- // top segment
- final Segment topSegment = new Segment(rect.getTopLeft(), rect.getTopRight());
- result = segment.getIntersection(topSegment);
-
- if (result == null) {
- // right segment
- final Segment rightSegment = new Segment(rect.getTopRight(), rect.getBottomRight());
- result = segment.getIntersection(rightSegment);
- }
-
- if (result == null) {
- // bottom segment
- final Segment bottomSegment = new Segment(rect.getBottomRight(), rect.getBottomLeft());
- result = segment.getIntersection(bottomSegment);
- }
-
- if (result == null) {
- // left segment
- final Segment leftSegment = new Segment(rect.getBottomLeft(), rect.getTopLeft());
- result = segment.getIntersection(leftSegment);
- }
- return result;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.geometry;
+
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.Rectangle;
+
+/**
+ *
+ * Utils class for drawd2D Rectangle
+ *
+ */
+public class RectangleUtils {
+
+ private RectangleUtils() {
+ // to prevent instantiation
+ }
+
+
+ /**
+ *
+ * @param rect
+ * a rectangle
+ * @param segment
+ * a segment
+ * @return
+ * the intersection point between the segment and the rectangle, if exists
+ */
+ public static final PrecisionPoint getIntersectionPoint(final Rectangle rect, final Segment segment) {
+ PrecisionPoint result = null;
+
+ // top segment
+ final Segment topSegment = new Segment(rect.getTopLeft(), rect.getTopRight());
+ result = segment.getIntersection(topSegment);
+
+ if (result == null) {
+ // right segment
+ final Segment rightSegment = new Segment(rect.getTopRight(), rect.getBottomRight());
+ result = segment.getIntersection(rightSegment);
+ }
+
+ if (result == null) {
+ // bottom segment
+ final Segment bottomSegment = new Segment(rect.getBottomRight(), rect.getBottomLeft());
+ result = segment.getIntersection(bottomSegment);
+ }
+
+ if (result == null) {
+ // left segment
+ final Segment leftSegment = new Segment(rect.getBottomLeft(), rect.getTopLeft());
+ result = segment.getIntersection(leftSegment);
+ }
+ return result;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java
index 1386ce9bf7e..a66c7ba408a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/geometry/Segment.java
@@ -1,138 +1,138 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.geometry;
-
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-
-/**
- *
- * This class is used to manipulate segment
- */
-public class Segment {
-
-
- /**
- * the start point of the segment
- */
- private final PrecisionPoint start;
-
- /**
- * the end point of the segment
- */
- private final PrecisionPoint end;
-
- /**
- *
- * Constructor.
- *
- * @param start
- * the start point of the segment
- * @param end
- * the end point of the segment
- */
- public Segment(final PrecisionPoint start, final PrecisionPoint end) {
- this.start = start.getPreciseCopy();
- this.end = end.getPreciseCopy();
- }
-
- /**
- *
- * Constructor.
- *
- * @param start
- * the start point of the segment
- * @param end
- * the end point of the segment
- */
- public Segment(final Point start, final Point end) {
- this.start = new PrecisionPoint(start);
- this.end = new PrecisionPoint(end);
- }
-
- /**
- *
- * @param segment
- * a segment
- * @return
- * <code>true</code> if the segment has a common point with this one
- */
- public boolean hasIntersection(final Segment segment) {
- return getIntersection(segment) != null;
- }
-
- /**
- *
- * @return
- * the start point of the segment
- */
- public final PrecisionPoint getStartPoint() {
- return this.start;
- }
-
- /**
- *
- * @return
- * the end point of the segment
- */
- public final PrecisionPoint getEndPoint() {
- return this.end;
- }
-
- // find line intersection in awt
- // static Point get_line_intersection(Line2D.Double pLine1, Line2D.Double pLine2) {
- // Point result = null;
- //
- // double s1_x = pLine1.x2 - pLine1.x1;
- // double s1_y = pLine1.y2 - pLine1.y1;
- // double s2_x = pLine2.x2 - pLine2.x1;
- // double s2_y = pLine2.y2 - pLine2.y1;
- //
- // double s = (-s1_y * (pLine1.x1 - pLine2.x1) + s1_x * (pLine1.y1 - pLine2.y1)) / (-s2_x * s1_y + s1_x * s2_y);
- // double t = (s2_x * (pLine1.y1 - pLine2.y1) - s2_y * (pLine1.x1 - pLine2.x1)) / (-s2_x * s1_y + s1_x * s2_y);
- //
- // if(s >= 0 && s <= 1 && t >= 0 && t <= 1) {
- // // Collision detected
- // result = new Point((int)(pLine1.x1 + (t * s1_x)), (int)(pLine1.y1 + (t * s1_y)));
- // } // end if
- //
- // return result;
- // }
-
- /**
- *
- * @param segment
- * a segment
- * @return
- * the intersection point if exists or <code>null</code>
- */
- public PrecisionPoint getIntersection(final Segment segment) {
- double s1_x = segment.getEndPoint().preciseX() - segment.getStartPoint().preciseX();
- double s1_y = segment.getEndPoint().preciseY() - segment.getStartPoint().preciseY();
- double s2_x = getEndPoint().preciseX() - getStartPoint().preciseX();
- double s2_y = getEndPoint().preciseY() - getStartPoint().preciseY();
- double s = (-s1_y * (segment.getStartPoint().preciseX() - getStartPoint().preciseX()) + s1_x * (segment.getStartPoint().preciseY() - getStartPoint().preciseY())) / (-s2_x * s1_y + s1_x * s2_y);
- double t = (s2_x * (segment.getStartPoint().preciseY() - getStartPoint().preciseY()) - s2_y * (segment.getStartPoint().preciseX() - getStartPoint().preciseX())) / (-s2_x * s1_y + s1_x * s2_y);
-
- PrecisionPoint result = null;
- if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
- // Collision detected
- result = new PrecisionPoint((int) (segment.getStartPoint().preciseX() + (t * s1_x)), (int) (segment.getStartPoint().preciseY() + (t * s1_y)));
- } // end if
-
- return result;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.geometry;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+
+/**
+ *
+ * This class is used to manipulate segment
+ */
+public class Segment {
+
+
+ /**
+ * the start point of the segment
+ */
+ private final PrecisionPoint start;
+
+ /**
+ * the end point of the segment
+ */
+ private final PrecisionPoint end;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param start
+ * the start point of the segment
+ * @param end
+ * the end point of the segment
+ */
+ public Segment(final PrecisionPoint start, final PrecisionPoint end) {
+ this.start = start.getPreciseCopy();
+ this.end = end.getPreciseCopy();
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param start
+ * the start point of the segment
+ * @param end
+ * the end point of the segment
+ */
+ public Segment(final Point start, final Point end) {
+ this.start = new PrecisionPoint(start);
+ this.end = new PrecisionPoint(end);
+ }
+
+ /**
+ *
+ * @param segment
+ * a segment
+ * @return
+ * <code>true</code> if the segment has a common point with this one
+ */
+ public boolean hasIntersection(final Segment segment) {
+ return getIntersection(segment) != null;
+ }
+
+ /**
+ *
+ * @return
+ * the start point of the segment
+ */
+ public final PrecisionPoint getStartPoint() {
+ return this.start;
+ }
+
+ /**
+ *
+ * @return
+ * the end point of the segment
+ */
+ public final PrecisionPoint getEndPoint() {
+ return this.end;
+ }
+
+ // find line intersection in awt
+ // static Point get_line_intersection(Line2D.Double pLine1, Line2D.Double pLine2) {
+ // Point result = null;
+ //
+ // double s1_x = pLine1.x2 - pLine1.x1;
+ // double s1_y = pLine1.y2 - pLine1.y1;
+ // double s2_x = pLine2.x2 - pLine2.x1;
+ // double s2_y = pLine2.y2 - pLine2.y1;
+ //
+ // double s = (-s1_y * (pLine1.x1 - pLine2.x1) + s1_x * (pLine1.y1 - pLine2.y1)) / (-s2_x * s1_y + s1_x * s2_y);
+ // double t = (s2_x * (pLine1.y1 - pLine2.y1) - s2_y * (pLine1.x1 - pLine2.x1)) / (-s2_x * s1_y + s1_x * s2_y);
+ //
+ // if(s >= 0 && s <= 1 && t >= 0 && t <= 1) {
+ // // Collision detected
+ // result = new Point((int)(pLine1.x1 + (t * s1_x)), (int)(pLine1.y1 + (t * s1_y)));
+ // } // end if
+ //
+ // return result;
+ // }
+
+ /**
+ *
+ * @param segment
+ * a segment
+ * @return
+ * the intersection point if exists or <code>null</code>
+ */
+ public PrecisionPoint getIntersection(final Segment segment) {
+ double s1_x = segment.getEndPoint().preciseX() - segment.getStartPoint().preciseX();
+ double s1_y = segment.getEndPoint().preciseY() - segment.getStartPoint().preciseY();
+ double s2_x = getEndPoint().preciseX() - getStartPoint().preciseX();
+ double s2_y = getEndPoint().preciseY() - getStartPoint().preciseY();
+ double s = (-s1_y * (segment.getStartPoint().preciseX() - getStartPoint().preciseX()) + s1_x * (segment.getStartPoint().preciseY() - getStartPoint().preciseY())) / (-s2_x * s1_y + s1_x * s2_y);
+ double t = (s2_x * (segment.getStartPoint().preciseY() - getStartPoint().preciseY()) - s2_y * (segment.getStartPoint().preciseX() - getStartPoint().preciseX())) / (-s2_x * s1_y + s1_x * s2_y);
+
+ PrecisionPoint result = null;
+ if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
+ // Collision detected
+ result = new PrecisionPoint((int) (segment.getStartPoint().preciseX() + (t * s1_x)), (int) (segment.getStartPoint().preciseY() + (t * s1_y)));
+ } // end if
+
+ return result;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java
index a37b8a4c098..aeec4cfc6d5 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/handler/IRefreshHandlerPart.java
@@ -1,29 +1,29 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.handler;
-
-import org.eclipse.ui.IEditorPart;
-
-/**
- * Represents a handler of refresh event
- *
- * @author Laurent Wouters
- */
-public interface IRefreshHandlerPart {
- /**
- * Refresh what needs to be, taking into account that the active editor is the given one
- *
- * @param editorPart
- * The currently active editor
- */
- void refresh(IEditorPart editorPart);
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Laurent Wouters (CEA LIST) laurent.wouters@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.handler;
+
+import org.eclipse.ui.IEditorPart;
+
+/**
+ * Represents a handler of refresh event
+ *
+ * @author Laurent Wouters
+ */
+public interface IRefreshHandlerPart {
+ /**
+ * Refresh what needs to be, taking into account that the active editor is the given one
+ *
+ * @param editorPart
+ * The currently active editor
+ */
+ void refresh(IEditorPart editorPart);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java
index 07b56a323f4..7d87a3a031d 100755
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/FixAnchorHelper.java
@@ -1,378 +1,378 @@
-/*****************************************************************************
- * Copyright (c) 2014 - 2017 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- * C�line Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 520154
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.helper;
-
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.draw2d.AbstractPointListShape;
-import org.eclipse.draw2d.ConnectionAnchor;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PointList;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.editparts.AbstractConnectionEditPart;
-import org.eclipse.gmf.runtime.common.core.command.CommandResult;
-import org.eclipse.gmf.runtime.common.core.command.ICommand;
-import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
-import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
-import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
-import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.IdentityAnchor;
-import org.eclipse.gmf.runtime.notation.NotationFactory;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- *
- * This class provides command to fix the anchors during a resize.
- * The methods are not static to allow to overriding
- *
- */
-public class FixAnchorHelper {
-
- /**
- * the editing domain used for the command
- */
- protected final TransactionalEditingDomain domain;
-
- /**
- * @since 3.1.0
- */
- private Rectangle includedRect;
-
-
- /**
- *
- * Constructor.
- *
- * @param domain
- * the editing domain to use, it must not be <code>null</code>
- */
- public FixAnchorHelper(final TransactionalEditingDomain domain) {
- Assert.isNotNull(domain);
- this.domain = domain;
- }
-
- /**
- *
- * @param node
- * the resized node
- * @param move
- * the move direction
- * @param sizeDelta
- * the delta of the size
- * @param moveDirection
- * the direction for the resize/move
- * @return
- * the command to fix the anchor or <code>null</code> if we can't fix it
- */
- public Command getFixIdentityAnchorCommand(final INodeEditPart node, final Point move, final Dimension sizeDelta, int moveDirection) {
- final CompoundCommand cc = new CompoundCommand("Fix All Anchors Command"); //$NON-NLS-1$
- // 1. we calculate the new bounds;
- final IFigure nodeFigure = node.getFigure();
- final PrecisionRectangle oldBounds = new PrecisionRectangle(nodeFigure.getBounds());
-
- // we translate the coordinates to absolute
- nodeFigure.translateToAbsolute(oldBounds);
- final PrecisionRectangle newBounds = oldBounds.getPreciseCopy();
- newBounds.translate(move.preciseX(), move.preciseY());
- newBounds.resize(sizeDelta.preciseWidth(), sizeDelta.preciseHeight());
-
-
- // 2. we iterate on the target anchor
- for (final Object targetConnection : node.getTargetConnections()) {
- if (targetConnection instanceof AbstractConnectionEditPart) {
- final Command tmp = getFixAnchorCommand(node, oldBounds, newBounds, (AbstractConnectionEditPart) targetConnection, move, sizeDelta, false);
- if (tmp != null) {
- cc.add(tmp);
- }
- }
- }
-
- // . we iterate on the source anchor
- for (final Object sourceConnection : node.getSourceConnections()) {
- if (sourceConnection instanceof AbstractConnectionEditPart) {
- final Command tmp = getFixAnchorCommand(node, oldBounds, newBounds, (AbstractConnectionEditPart) sourceConnection, move, sizeDelta, true);
- if (tmp != null) {
- cc.add(tmp);
- }
- }
- }
-
- if (cc.isEmpty()) {
- return null;
- }
- return cc;
- }
-
- /**
- *
- * @param edgeEP
- * the edge edit part
- * @param sourcePoint
- * if <code>true</code> we return the source point and if false we return the end point
- * @return
- * the real point to fix
- */
- protected Point getRealAnchorPoint(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint) {
- final IFigure figure = edgeEP.getFigure();
- Point point = null;
- if (figure instanceof AbstractPointListShape) {
- if (sourcePoint) {
- point = ((AbstractPointListShape) figure).getStart().getCopy();
- } else {
- point = ((AbstractPointListShape) figure).getEnd().getCopy();
- }
- }
- figure.translateToAbsolute(point);
- return point;
- }
-
- /**
- *
- * @param edgeEP
- * the edge edit part
- * @param sourcePoint
- * if <code>true</code> we return the source point and if false we return the end point
- * @param nodeEP
- * the node edit part
- * @param p
- * the real anchor point in absolute coordinate
- * @return
- * the anchor representing the point to fix
- */
- protected IdentityAnchor getIdentityAnchor(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint, final INodeEditPart nodeEP, final Point p) {
- final View view = (View) edgeEP.getAdapter(View.class);
- IdentityAnchor anchor = null;
- if (view instanceof Edge) {
- final Object tmpAnchor;
- if (sourcePoint) {
- tmpAnchor = ((Edge) view).getSourceAnchor();
- } else {
- tmpAnchor = ((Edge) view).getTargetAnchor();
- }
- if (tmpAnchor instanceof IdentityAnchor) {
- anchor = (IdentityAnchor) tmpAnchor;
- }
- if (anchor == null) {
- ConnectionAnchor connectionAnchor = null;
- if (nodeEP.getFigure() instanceof NodeFigure) {
- NodeFigure nodeFigure = (NodeFigure) nodeEP.getFigure();
- if (sourcePoint) {
- connectionAnchor = nodeFigure.getSourceConnectionAnchorAt(p);
- } else {
- connectionAnchor = nodeFigure.getTargetConnectionAnchorAt(p);
- }
- if (connectionAnchor != null) {
- final String id = nodeEP.mapConnectionAnchorToTerminal(connectionAnchor);
- anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
- anchor.setId(id);
- }
- }
- }
-
- }
- return anchor;
-
- }
-
- /**
- *
- * @param nodeEditPart
- * the resized edit part
- * @param oldNodeBounds
- * the old bounds for this edit part
- * @param newNodeBounds
- * the new bounds for this edit part
- * @param targetConnectionEP
- * the edit part of the connection for which we want fix anchor
- * @param move
- * the move
- * @param sizeDelta
- * the delta of the resize
- * @param fixSource
- * if <code>true</code> we are fixing the source anchor if <code>false</code> we are fixing the target anchor
- * @return
- */
- public Command getFixAnchorCommand(final INodeEditPart nodeEditPart, final PrecisionRectangle oldNodeBounds, final PrecisionRectangle newNodeBounds, final AbstractConnectionEditPart targetConnectionEP, final Point move, final Dimension sizeDelta,
- final boolean fixSource) {
- final Point realAnchorPoint = getRealAnchorPoint(targetConnectionEP, fixSource);
-
- final IFigure fig = nodeEditPart.getFigure();
- if (fig instanceof NodeFigure) {
- final NodeFigure nodeFigure = (NodeFigure) fig;
- final IdentityAnchor editedAnchor = getIdentityAnchor(targetConnectionEP, fixSource, nodeEditPart, realAnchorPoint);
- if (realAnchorPoint != null && editedAnchor != null) {
-
- final View view = (View) targetConnectionEP.getAdapter(View.class);
- if (view instanceof Edge) {
- // 1. get the real side on which start/end the manipulated anchor
- final int anchorSide = getSideOfConnectionPoint(nodeFigure, targetConnectionEP, fixSource);
- // 2. determine the new values
- double newX = -1;
- double newY = -1;
- switch (anchorSide) {
- case PositionConstants.NORTH:
- newY = 0;
- break;
- case PositionConstants.WEST:
- newX = 0;
- break;
- case PositionConstants.EAST:
- newX = 1;
- break;
- case PositionConstants.SOUTH:
- newY = 1;
- break;
- default:
- // other case not yet manager because they are resize dependant!
- break;
- }
-
- PrecisionPoint newRealAnchorPoint = new PrecisionPoint(realAnchorPoint);
- newRealAnchorPoint.setPreciseLocation(newRealAnchorPoint.x() - oldNodeBounds.preciseX(), newRealAnchorPoint.y() - oldNodeBounds.preciseY());
-
- PrecisionPoint newLocation = newRealAnchorPoint.getPreciseCopy();
- newLocation.setPreciseX(newLocation.preciseX() - move.preciseX());
- newLocation.setPreciseY(newLocation.preciseY() - move.preciseY());
-
- if (newX == -1) {
- newX = newLocation.preciseX() / newNodeBounds.preciseWidth();
- }
- if (newY == -1) {
- newY = newLocation.preciseY() / newNodeBounds.preciseHeight();
- }
-
- if (newX <= 1 && newX >= 0 && newY <= 1 && newY >= 0) {
- final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(newX, newY);
- final ICommand cmd = new AbstractTransactionalCommand(this.domain, "Fix Anchor Location", null) { //$NON-NLS-1$
-
- @Override
- protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
- editedAnchor.setId(newIdValue);
-
- if (editedAnchor.eContainer() == null) {
- if (fixSource) {
- ((Edge) view).setSourceAnchor(editedAnchor);
- } else {
- ((Edge) view).setTargetAnchor(editedAnchor);
- }
- }
- return CommandResult.newOKCommandResult(editedAnchor);
- }
- };
- return new ICommandProxy(cmd);
- }
- }
- }
- }
- return null;
- }
-
- /**
- *
- * @param nodeFigure
- * the node figure
- * @param edgeEP
- * the connection edit part
- * @param fixingSource
- * if <code>true</code> we are fixing the source anchor and if <code>false</code> we are fixing the target anchor
- * @return
- * the direction of the manipulated anchor (according to {@link PositionConstants}
- */
- protected int getSideOfConnectionPoint(final IFigure nodeFigure, final AbstractConnectionEditPart edgeEP, final boolean fixingSource) {
- int side = -1;
- final IFigure figure = edgeEP.getFigure();
- if (figure instanceof PolylineConnectionEx) {
- final PolylineConnectionEx connection = (PolylineConnectionEx) figure;
- final Rectangle bounds = nodeFigure.getBounds().getCopy();
- nodeFigure.translateToAbsolute(bounds);
- final Point pt;
- if (fixingSource) {
- pt = connection.getStart();
- } else {
- pt = connection.getEnd();
- }
- figure.translateToAbsolute(pt);
- setIncludedRect(bounds.getCopy());
-
- side = getSideFromRectangle(pt);
- // if the anchor side is a corner, we determine its side using another point
- if (side == PositionConstants.NORTH_WEST || side == PositionConstants.NORTH_EAST || side == PositionConstants.SOUTH_EAST || side == PositionConstants.SOUTH_WEST) {
- final Point previousPoint;
- final PointList list = connection.getPoints();
- if (list.size() > 1) {
-
- if (fixingSource) {
- previousPoint = list.getPoint(1);
- } else {
- previousPoint = list.getPoint(list.size() - 2);
- }
- nodeFigure.translateToAbsolute(previousPoint.getCopy());
- while (getIncludedRect().contains(previousPoint)) {
- getIncludedRect().shrink(1, 1);
- }
- side = getIncludedRect().getPosition(previousPoint);
- }
- }
- }
- return side;
- }
-
- /**
- * Return the side of the point on the included Rectangle
- *
- * @since 3.1
- * @param pt
- * Point with absolute position
- * @return integer representing the position from PositionConstants.
- *
- */
- protected int getSideFromRectangle(Point pt) {
- while (getIncludedRect().contains(pt)) {
- getIncludedRect().shrink(1, 1);
- }
- int side = getIncludedRect().getPosition(pt);
-
- return side;
- }
-
- /**
- * @return the includedRect
- * @since 3.1
- */
- public Rectangle getIncludedRect() {
- return includedRect;
- }
-
- /**
- * @param includedRect
- * the includedRect to set
- * @since 3.1
- */
- public void setIncludedRect(Rectangle includedRect) {
- this.includedRect = includedRect;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 - 2017 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ * C�line Janssens (ALL4TEC) celine.janssens@all4tec.net - Bug 520154
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.draw2d.AbstractPointListShape;
+import org.eclipse.draw2d.ConnectionAnchor;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PointList;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.editparts.AbstractConnectionEditPart;
+import org.eclipse.gmf.runtime.common.core.command.CommandResult;
+import org.eclipse.gmf.runtime.common.core.command.ICommand;
+import org.eclipse.gmf.runtime.diagram.ui.commands.ICommandProxy;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.INodeEditPart;
+import org.eclipse.gmf.runtime.draw2d.ui.figures.PolylineConnectionEx;
+import org.eclipse.gmf.runtime.emf.commands.core.command.AbstractTransactionalCommand;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
+import org.eclipse.gmf.runtime.notation.NotationFactory;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ *
+ * This class provides command to fix the anchors during a resize.
+ * The methods are not static to allow to overriding
+ *
+ */
+public class FixAnchorHelper {
+
+ /**
+ * the editing domain used for the command
+ */
+ protected final TransactionalEditingDomain domain;
+
+ /**
+ * @since 3.1.0
+ */
+ private Rectangle includedRect;
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param domain
+ * the editing domain to use, it must not be <code>null</code>
+ */
+ public FixAnchorHelper(final TransactionalEditingDomain domain) {
+ Assert.isNotNull(domain);
+ this.domain = domain;
+ }
+
+ /**
+ *
+ * @param node
+ * the resized node
+ * @param move
+ * the move direction
+ * @param sizeDelta
+ * the delta of the size
+ * @param moveDirection
+ * the direction for the resize/move
+ * @return
+ * the command to fix the anchor or <code>null</code> if we can't fix it
+ */
+ public Command getFixIdentityAnchorCommand(final INodeEditPart node, final Point move, final Dimension sizeDelta, int moveDirection) {
+ final CompoundCommand cc = new CompoundCommand("Fix All Anchors Command"); //$NON-NLS-1$
+ // 1. we calculate the new bounds;
+ final IFigure nodeFigure = node.getFigure();
+ final PrecisionRectangle oldBounds = new PrecisionRectangle(nodeFigure.getBounds());
+
+ // we translate the coordinates to absolute
+ nodeFigure.translateToAbsolute(oldBounds);
+ final PrecisionRectangle newBounds = oldBounds.getPreciseCopy();
+ newBounds.translate(move.preciseX(), move.preciseY());
+ newBounds.resize(sizeDelta.preciseWidth(), sizeDelta.preciseHeight());
+
+
+ // 2. we iterate on the target anchor
+ for (final Object targetConnection : node.getTargetConnections()) {
+ if (targetConnection instanceof AbstractConnectionEditPart) {
+ final Command tmp = getFixAnchorCommand(node, oldBounds, newBounds, (AbstractConnectionEditPart) targetConnection, move, sizeDelta, false);
+ if (tmp != null) {
+ cc.add(tmp);
+ }
+ }
+ }
+
+ // . we iterate on the source anchor
+ for (final Object sourceConnection : node.getSourceConnections()) {
+ if (sourceConnection instanceof AbstractConnectionEditPart) {
+ final Command tmp = getFixAnchorCommand(node, oldBounds, newBounds, (AbstractConnectionEditPart) sourceConnection, move, sizeDelta, true);
+ if (tmp != null) {
+ cc.add(tmp);
+ }
+ }
+ }
+
+ if (cc.isEmpty()) {
+ return null;
+ }
+ return cc;
+ }
+
+ /**
+ *
+ * @param edgeEP
+ * the edge edit part
+ * @param sourcePoint
+ * if <code>true</code> we return the source point and if false we return the end point
+ * @return
+ * the real point to fix
+ */
+ protected Point getRealAnchorPoint(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint) {
+ final IFigure figure = edgeEP.getFigure();
+ Point point = null;
+ if (figure instanceof AbstractPointListShape) {
+ if (sourcePoint) {
+ point = ((AbstractPointListShape) figure).getStart().getCopy();
+ } else {
+ point = ((AbstractPointListShape) figure).getEnd().getCopy();
+ }
+ }
+ figure.translateToAbsolute(point);
+ return point;
+ }
+
+ /**
+ *
+ * @param edgeEP
+ * the edge edit part
+ * @param sourcePoint
+ * if <code>true</code> we return the source point and if false we return the end point
+ * @param nodeEP
+ * the node edit part
+ * @param p
+ * the real anchor point in absolute coordinate
+ * @return
+ * the anchor representing the point to fix
+ */
+ protected IdentityAnchor getIdentityAnchor(final AbstractConnectionEditPart edgeEP, final boolean sourcePoint, final INodeEditPart nodeEP, final Point p) {
+ final View view = (View) edgeEP.getAdapter(View.class);
+ IdentityAnchor anchor = null;
+ if (view instanceof Edge) {
+ final Object tmpAnchor;
+ if (sourcePoint) {
+ tmpAnchor = ((Edge) view).getSourceAnchor();
+ } else {
+ tmpAnchor = ((Edge) view).getTargetAnchor();
+ }
+ if (tmpAnchor instanceof IdentityAnchor) {
+ anchor = (IdentityAnchor) tmpAnchor;
+ }
+ if (anchor == null) {
+ ConnectionAnchor connectionAnchor = null;
+ if (nodeEP.getFigure() instanceof NodeFigure) {
+ NodeFigure nodeFigure = (NodeFigure) nodeEP.getFigure();
+ if (sourcePoint) {
+ connectionAnchor = nodeFigure.getSourceConnectionAnchorAt(p);
+ } else {
+ connectionAnchor = nodeFigure.getTargetConnectionAnchorAt(p);
+ }
+ if (connectionAnchor != null) {
+ final String id = nodeEP.mapConnectionAnchorToTerminal(connectionAnchor);
+ anchor = NotationFactory.eINSTANCE.createIdentityAnchor();
+ anchor.setId(id);
+ }
+ }
+ }
+
+ }
+ return anchor;
+
+ }
+
+ /**
+ *
+ * @param nodeEditPart
+ * the resized edit part
+ * @param oldNodeBounds
+ * the old bounds for this edit part
+ * @param newNodeBounds
+ * the new bounds for this edit part
+ * @param targetConnectionEP
+ * the edit part of the connection for which we want fix anchor
+ * @param move
+ * the move
+ * @param sizeDelta
+ * the delta of the resize
+ * @param fixSource
+ * if <code>true</code> we are fixing the source anchor if <code>false</code> we are fixing the target anchor
+ * @return
+ */
+ public Command getFixAnchorCommand(final INodeEditPart nodeEditPart, final PrecisionRectangle oldNodeBounds, final PrecisionRectangle newNodeBounds, final AbstractConnectionEditPart targetConnectionEP, final Point move, final Dimension sizeDelta,
+ final boolean fixSource) {
+ final Point realAnchorPoint = getRealAnchorPoint(targetConnectionEP, fixSource);
+
+ final IFigure fig = nodeEditPart.getFigure();
+ if (fig instanceof NodeFigure) {
+ final NodeFigure nodeFigure = (NodeFigure) fig;
+ final IdentityAnchor editedAnchor = getIdentityAnchor(targetConnectionEP, fixSource, nodeEditPart, realAnchorPoint);
+ if (realAnchorPoint != null && editedAnchor != null) {
+
+ final View view = (View) targetConnectionEP.getAdapter(View.class);
+ if (view instanceof Edge) {
+ // 1. get the real side on which start/end the manipulated anchor
+ final int anchorSide = getSideOfConnectionPoint(nodeFigure, targetConnectionEP, fixSource);
+ // 2. determine the new values
+ double newX = -1;
+ double newY = -1;
+ switch (anchorSide) {
+ case PositionConstants.NORTH:
+ newY = 0;
+ break;
+ case PositionConstants.WEST:
+ newX = 0;
+ break;
+ case PositionConstants.EAST:
+ newX = 1;
+ break;
+ case PositionConstants.SOUTH:
+ newY = 1;
+ break;
+ default:
+ // other case not yet manager because they are resize dependant!
+ break;
+ }
+
+ PrecisionPoint newRealAnchorPoint = new PrecisionPoint(realAnchorPoint);
+ newRealAnchorPoint.setPreciseLocation(newRealAnchorPoint.x() - oldNodeBounds.preciseX(), newRealAnchorPoint.y() - oldNodeBounds.preciseY());
+
+ PrecisionPoint newLocation = newRealAnchorPoint.getPreciseCopy();
+ newLocation.setPreciseX(newLocation.preciseX() - move.preciseX());
+ newLocation.setPreciseY(newLocation.preciseY() - move.preciseY());
+
+ if (newX == -1) {
+ newX = newLocation.preciseX() / newNodeBounds.preciseWidth();
+ }
+ if (newY == -1) {
+ newY = newLocation.preciseY() / newNodeBounds.preciseHeight();
+ }
+
+ if (newX <= 1 && newX >= 0 && newY <= 1 && newY >= 0) {
+ final String newIdValue = IdentityAnchorHelper.createNewAnchorIdValue(newX, newY);
+ final ICommand cmd = new AbstractTransactionalCommand(this.domain, "Fix Anchor Location", null) { //$NON-NLS-1$
+
+ @Override
+ protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
+ editedAnchor.setId(newIdValue);
+
+ if (editedAnchor.eContainer() == null) {
+ if (fixSource) {
+ ((Edge) view).setSourceAnchor(editedAnchor);
+ } else {
+ ((Edge) view).setTargetAnchor(editedAnchor);
+ }
+ }
+ return CommandResult.newOKCommandResult(editedAnchor);
+ }
+ };
+ return new ICommandProxy(cmd);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * @param nodeFigure
+ * the node figure
+ * @param edgeEP
+ * the connection edit part
+ * @param fixingSource
+ * if <code>true</code> we are fixing the source anchor and if <code>false</code> we are fixing the target anchor
+ * @return
+ * the direction of the manipulated anchor (according to {@link PositionConstants}
+ */
+ protected int getSideOfConnectionPoint(final IFigure nodeFigure, final AbstractConnectionEditPart edgeEP, final boolean fixingSource) {
+ int side = -1;
+ final IFigure figure = edgeEP.getFigure();
+ if (figure instanceof PolylineConnectionEx) {
+ final PolylineConnectionEx connection = (PolylineConnectionEx) figure;
+ final Rectangle bounds = nodeFigure.getBounds().getCopy();
+ nodeFigure.translateToAbsolute(bounds);
+ final Point pt;
+ if (fixingSource) {
+ pt = connection.getStart();
+ } else {
+ pt = connection.getEnd();
+ }
+ figure.translateToAbsolute(pt);
+ setIncludedRect(bounds.getCopy());
+
+ side = getSideFromRectangle(pt);
+ // if the anchor side is a corner, we determine its side using another point
+ if (side == PositionConstants.NORTH_WEST || side == PositionConstants.NORTH_EAST || side == PositionConstants.SOUTH_EAST || side == PositionConstants.SOUTH_WEST) {
+ final Point previousPoint;
+ final PointList list = connection.getPoints();
+ if (list.size() > 1) {
+
+ if (fixingSource) {
+ previousPoint = list.getPoint(1);
+ } else {
+ previousPoint = list.getPoint(list.size() - 2);
+ }
+ nodeFigure.translateToAbsolute(previousPoint.getCopy());
+ while (getIncludedRect().contains(previousPoint)) {
+ getIncludedRect().shrink(1, 1);
+ }
+ side = getIncludedRect().getPosition(previousPoint);
+ }
+ }
+ }
+ return side;
+ }
+
+ /**
+ * Return the side of the point on the included Rectangle
+ *
+ * @since 3.1
+ * @param pt
+ * Point with absolute position
+ * @return integer representing the position from PositionConstants.
+ *
+ */
+ protected int getSideFromRectangle(Point pt) {
+ while (getIncludedRect().contains(pt)) {
+ getIncludedRect().shrink(1, 1);
+ }
+ int side = getIncludedRect().getPosition(pt);
+
+ return side;
+ }
+
+ /**
+ * @return the includedRect
+ * @since 3.1
+ */
+ public Rectangle getIncludedRect() {
+ return includedRect;
+ }
+
+ /**
+ * @param includedRect
+ * the includedRect to set
+ * @since 3.1
+ */
+ public void setIncludedRect(Rectangle includedRect) {
+ this.includedRect = includedRect;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
index 8e8d5f0243e..9fd8182aa2e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/IdentityAnchorHelper.java
@@ -1,106 +1,106 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.helper;
-
-import org.eclipse.gmf.runtime.notation.IdentityAnchor;
-
-/**
- *
- * Helper used for identity anchor
- *
- */
-public class IdentityAnchorHelper {
-
- /**
- * the char starting an id of {@link IdentityAnchor}
- */
- public static final char START_ID = '(';
-
- /**
- * the char ending an id of {@link IdentityAnchor}
- */
-
- public static final char END_ID = ')';
-
- /**
- * the char separating percentage in ids of {@link IdentityAnchor}
- */
- public static final char X_Y_SEPARATOR = ',';
-
- /**
- * the char separating percentage as string in ids of {@link IdentityAnchor}
- */
- public static final String X_Y_SEPARATOR_AS_STRING = new String(new char[] { X_Y_SEPARATOR });
-
- /**
- *
- * Constructor.
- *
- */
- private IdentityAnchorHelper() {
- // to prevent instanciation
- }
-
- /**
- *
- * @param anchor
- * an anchor
- * @return
- * the value of x percentage
- */
- public static final double getXPercentage(final IdentityAnchor anchor) {
- String id = anchor.getId();
- id = id.substring(1, id.indexOf(X_Y_SEPARATOR_AS_STRING));
- return Double.parseDouble(id);
- }
-
- /**
- *
- * @param anchor
- * an anchor
- * @return
- * the value of y percentage
- */
- public static final double getYPercentage(final IdentityAnchor anchor) {
- String id = anchor.getId();
- if(id.indexOf(X_Y_SEPARATOR_AS_STRING)==-1) {
- return 0;
- }
- id = id.substring(id.indexOf(X_Y_SEPARATOR_AS_STRING) + 1, id.length() - 1);
- if(id.indexOf(END_ID)!=-1){
- id = id.substring(0, id.indexOf(END_ID));
- }
- return Double.parseDouble(id);
- }
-
-
- /**
- *
- * @param percentageOnX
- * the percentage on x
- * @param percentageOnY
- * the percentage on y
- * @return
- * the string representing the new id for an anchor
- */
- public static final String createNewAnchorIdValue(final double percentageOnX, final double percentageOnY) {
- final StringBuffer buffer = new StringBuffer();
- buffer.append(START_ID);
- buffer.append(Double.toString(percentageOnX));
- buffer.append(X_Y_SEPARATOR_AS_STRING);
- buffer.append(Double.toString(percentageOnY));
- buffer.append(END_ID);
- return buffer.toString();
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import org.eclipse.gmf.runtime.notation.IdentityAnchor;
+
+/**
+ *
+ * Helper used for identity anchor
+ *
+ */
+public class IdentityAnchorHelper {
+
+ /**
+ * the char starting an id of {@link IdentityAnchor}
+ */
+ public static final char START_ID = '(';
+
+ /**
+ * the char ending an id of {@link IdentityAnchor}
+ */
+
+ public static final char END_ID = ')';
+
+ /**
+ * the char separating percentage in ids of {@link IdentityAnchor}
+ */
+ public static final char X_Y_SEPARATOR = ',';
+
+ /**
+ * the char separating percentage as string in ids of {@link IdentityAnchor}
+ */
+ public static final String X_Y_SEPARATOR_AS_STRING = new String(new char[] { X_Y_SEPARATOR });
+
+ /**
+ *
+ * Constructor.
+ *
+ */
+ private IdentityAnchorHelper() {
+ // to prevent instanciation
+ }
+
+ /**
+ *
+ * @param anchor
+ * an anchor
+ * @return
+ * the value of x percentage
+ */
+ public static final double getXPercentage(final IdentityAnchor anchor) {
+ String id = anchor.getId();
+ id = id.substring(1, id.indexOf(X_Y_SEPARATOR_AS_STRING));
+ return Double.parseDouble(id);
+ }
+
+ /**
+ *
+ * @param anchor
+ * an anchor
+ * @return
+ * the value of y percentage
+ */
+ public static final double getYPercentage(final IdentityAnchor anchor) {
+ String id = anchor.getId();
+ if(id.indexOf(X_Y_SEPARATOR_AS_STRING)==-1) {
+ return 0;
+ }
+ id = id.substring(id.indexOf(X_Y_SEPARATOR_AS_STRING) + 1, id.length() - 1);
+ if(id.indexOf(END_ID)!=-1){
+ id = id.substring(0, id.indexOf(END_ID));
+ }
+ return Double.parseDouble(id);
+ }
+
+
+ /**
+ *
+ * @param percentageOnX
+ * the percentage on x
+ * @param percentageOnY
+ * the percentage on y
+ * @return
+ * the string representing the new id for an anchor
+ */
+ public static final String createNewAnchorIdValue(final double percentageOnX, final double percentageOnY) {
+ final StringBuffer buffer = new StringBuffer();
+ buffer.append(START_ID);
+ buffer.append(Double.toString(percentageOnX));
+ buffer.append(X_Y_SEPARATOR_AS_STRING);
+ buffer.append(Double.toString(percentageOnY));
+ buffer.append(END_ID);
+ return buffer.toString();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java
index b8a157cb41b..14c61d04c56 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/NotationHelper.java
@@ -1,123 +1,123 @@
-/*****************************************************************************
- * Copyright (c) 2012, 2014 CEA LIST 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- * Christian W. Damus (CEA) - bug 386118
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.helper;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Bounds;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-
-/**
- * A Helper class related to the GMF Notation metamodel.
- *
- * @author Camille Letavernier
- */
-public class NotationHelper {
-
- /**
- * Retrieves the GMF View associated to the source object
- *
- * @param source
- * the source
- * @return the resolved view, or null if it cannot be found
- */
- public static View findView(Object source) {
- if (source instanceof View) {
- return (View) source;
- }
-
- if (source instanceof IAdaptable) {
- IAdaptable adaptable = (IAdaptable) source;
- Object adapter = adaptable.getAdapter(View.class);
- if (adapter instanceof View) {
- return (View) adapter;
- }
- }
-
- if (source != null) {
- return Platform.getAdapterManager().getAdapter(source, View.class);
- }
-
- EObject obj = EMFHelper.getEObject(source);
- return (obj instanceof View) ? (View) obj : null;
- }
-
- /**
- * Tests whether the given View is a reference to an external element.
- * A view is an external reference if its graphical container is different from its semantic
- * container (i.e. self.element.eContainer() != self.primaryView.eContainer().element)
- *
- * @param diagramElement
- * @return
- */
- public static boolean isExternalRef(View diagramElement) {
- if (diagramElement == null) {
- return false;
- }
-
- View primaryView = SemanticElementHelper.findTopView(diagramElement);
- if (primaryView == null) {
- return false;
- }
-
- EObject semanticElement = primaryView.getElement();
-
- if (semanticElement == null) {
- return false;
- }
-
- EObject parentView = primaryView.eContainer();
- if (!(parentView instanceof View)) {
- return false;
- }
-
- EObject parentSemanticElement = ((View) parentView).getElement();
- if (parentSemanticElement == null) {
- return false;
- }
-
- // Relax the constraints for elements displayed on themselves (e.g. Frame in Composite Structure Diagram)
- return parentSemanticElement != semanticElement.eContainer() && parentSemanticElement != semanticElement;
- }
-
- /**
- * get the absolute position form the notation
- *
- * @param node
- * the current node
- * @return
- * @since 3.0
- */
- public static PrecisionRectangle getAbsoluteBounds(Node node) {
- if (node.getLayoutConstraint() instanceof Bounds) {
- PrecisionRectangle bounds = new PrecisionRectangle(((Bounds) node.getLayoutConstraint()).getX(), ((Bounds) node.getLayoutConstraint()).getY(), ((Bounds) node.getLayoutConstraint()).getWidth(), ((Bounds) node.getLayoutConstraint()).getHeight());
- EObject currentView = (EObject) node.eContainer();
- while (currentView != null) {
-
- if (currentView instanceof Node) {
- Point ptCurrenview = new Point(((Bounds) ((Node) currentView).getLayoutConstraint()).getX(), ((Bounds) ((Node) currentView).getLayoutConstraint()).getY());
- bounds.translate(ptCurrenview);
- }
- currentView = currentView.eContainer();
- }
- return bounds;
- } else
- return null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2014 CEA LIST 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ * Christian W. Damus (CEA) - bug 386118
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Bounds;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+
+/**
+ * A Helper class related to the GMF Notation metamodel.
+ *
+ * @author Camille Letavernier
+ */
+public class NotationHelper {
+
+ /**
+ * Retrieves the GMF View associated to the source object
+ *
+ * @param source
+ * the source
+ * @return the resolved view, or null if it cannot be found
+ */
+ public static View findView(Object source) {
+ if (source instanceof View) {
+ return (View) source;
+ }
+
+ if (source instanceof IAdaptable) {
+ IAdaptable adaptable = (IAdaptable) source;
+ Object adapter = adaptable.getAdapter(View.class);
+ if (adapter instanceof View) {
+ return (View) adapter;
+ }
+ }
+
+ if (source != null) {
+ return Platform.getAdapterManager().getAdapter(source, View.class);
+ }
+
+ EObject obj = EMFHelper.getEObject(source);
+ return (obj instanceof View) ? (View) obj : null;
+ }
+
+ /**
+ * Tests whether the given View is a reference to an external element.
+ * A view is an external reference if its graphical container is different from its semantic
+ * container (i.e. self.element.eContainer() != self.primaryView.eContainer().element)
+ *
+ * @param diagramElement
+ * @return
+ */
+ public static boolean isExternalRef(View diagramElement) {
+ if (diagramElement == null) {
+ return false;
+ }
+
+ View primaryView = SemanticElementHelper.findTopView(diagramElement);
+ if (primaryView == null) {
+ return false;
+ }
+
+ EObject semanticElement = primaryView.getElement();
+
+ if (semanticElement == null) {
+ return false;
+ }
+
+ EObject parentView = primaryView.eContainer();
+ if (!(parentView instanceof View)) {
+ return false;
+ }
+
+ EObject parentSemanticElement = ((View) parentView).getElement();
+ if (parentSemanticElement == null) {
+ return false;
+ }
+
+ // Relax the constraints for elements displayed on themselves (e.g. Frame in Composite Structure Diagram)
+ return parentSemanticElement != semanticElement.eContainer() && parentSemanticElement != semanticElement;
+ }
+
+ /**
+ * get the absolute position form the notation
+ *
+ * @param node
+ * the current node
+ * @return
+ * @since 3.0
+ */
+ public static PrecisionRectangle getAbsoluteBounds(Node node) {
+ if (node.getLayoutConstraint() instanceof Bounds) {
+ PrecisionRectangle bounds = new PrecisionRectangle(((Bounds) node.getLayoutConstraint()).getX(), ((Bounds) node.getLayoutConstraint()).getY(), ((Bounds) node.getLayoutConstraint()).getWidth(), ((Bounds) node.getLayoutConstraint()).getHeight());
+ EObject currentView = (EObject) node.eContainer();
+ while (currentView != null) {
+
+ if (currentView instanceof Node) {
+ Point ptCurrenview = new Point(((Bounds) ((Node) currentView).getLayoutConstraint()).getX(), ((Bounds) ((Node) currentView).getLayoutConstraint()).getY());
+ bounds.translate(ptCurrenview);
+ }
+ currentView = currentView.eContainer();
+ }
+ return bounds;
+ } else
+ return null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/SemanticElementHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/SemanticElementHelper.java
index 0643b255203..e971b0c4f33 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/SemanticElementHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/helper/SemanticElementHelper.java
@@ -1,112 +1,112 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.helper;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.emf.Activator;
-
-/**
- * A Helper for retrieving Views and Semantic elements from a
- * compatible object.
- *
- * @author Camille Letavernier
- */
-public class SemanticElementHelper {
-
- /**
- * Returns the semantic element attached to the given notation element
- *
- * The result element can also be a Diagram
- *
- * @param notationElement
- * @return
- */
- public static EObject findSemanticElement(EObject notationElement) {
- if (notationElement == null) {
- return null;
- }
-
- if (notationElement instanceof Diagram) {
- return notationElement;
- }
-
- if (notationElement instanceof View) {
- View view = (View) notationElement;
- EObject semanticElement = view.getElement();
- if (semanticElement != null) {
- return semanticElement;
- }
-
- // The graphical element isn't related to a Semantic Element. The view becomes the semantic element.
- // e.g. : Links in UML
- return view;
- }
-
- EObject currentElement = notationElement.eContainer();
-
- do {
- if (currentElement instanceof View) {
- return findSemanticElement(currentElement);
- }
- currentElement = currentElement.eContainer();
- } while (currentElement != null);
-
- Activator.log.warn("Cannot find a valid source for " + notationElement);
- return notationElement;
- }
-
- /**
- * Retrieves the primary view associated to the argument.
- *
- * For example, for a compartment, this method will return the top-most
- * view associated to the same semantic element.
- *
- * @param notationElement
- * @return
- */
- // @unused
- public static View findPrimaryView(EObject notationElement) {
- return findTopView(notationElement);
- }
-
- /**
- * Finds the top-most View associated to the same semantic
- * element as the argument.
- *
- * @param notationElement
- * @return
- */
- // @unused
- public static View findTopView(EObject notationElement) {
- EObject semanticElement = findSemanticElement(notationElement);
-
- if (semanticElement == notationElement) {
- return (View) notationElement;
- }
-
- EObject lastNotationElement = notationElement;
- while (notationElement != null) {
- notationElement = notationElement.eContainer();
- if (findSemanticElement(notationElement) != semanticElement) {
- return (View) lastNotationElement;
- }
-
- if (notationElement != null) {
- lastNotationElement = notationElement;
- }
- }
-
- return (View) lastNotationElement;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.helper;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.emf.Activator;
+
+/**
+ * A Helper for retrieving Views and Semantic elements from a
+ * compatible object.
+ *
+ * @author Camille Letavernier
+ */
+public class SemanticElementHelper {
+
+ /**
+ * Returns the semantic element attached to the given notation element
+ *
+ * The result element can also be a Diagram
+ *
+ * @param notationElement
+ * @return
+ */
+ public static EObject findSemanticElement(EObject notationElement) {
+ if (notationElement == null) {
+ return null;
+ }
+
+ if (notationElement instanceof Diagram) {
+ return notationElement;
+ }
+
+ if (notationElement instanceof View) {
+ View view = (View) notationElement;
+ EObject semanticElement = view.getElement();
+ if (semanticElement != null) {
+ return semanticElement;
+ }
+
+ // The graphical element isn't related to a Semantic Element. The view becomes the semantic element.
+ // e.g. : Links in UML
+ return view;
+ }
+
+ EObject currentElement = notationElement.eContainer();
+
+ do {
+ if (currentElement instanceof View) {
+ return findSemanticElement(currentElement);
+ }
+ currentElement = currentElement.eContainer();
+ } while (currentElement != null);
+
+ Activator.log.warn("Cannot find a valid source for " + notationElement);
+ return notationElement;
+ }
+
+ /**
+ * Retrieves the primary view associated to the argument.
+ *
+ * For example, for a compartment, this method will return the top-most
+ * view associated to the same semantic element.
+ *
+ * @param notationElement
+ * @return
+ */
+ // @unused
+ public static View findPrimaryView(EObject notationElement) {
+ return findTopView(notationElement);
+ }
+
+ /**
+ * Finds the top-most View associated to the same semantic
+ * element as the argument.
+ *
+ * @param notationElement
+ * @return
+ */
+ // @unused
+ public static View findTopView(EObject notationElement) {
+ EObject semanticElement = findSemanticElement(notationElement);
+
+ if (semanticElement == notationElement) {
+ return (View) notationElement;
+ }
+
+ EObject lastNotationElement = notationElement;
+ while (notationElement != null) {
+ notationElement = notationElement.eContainer();
+ if (findSemanticElement(notationElement) != semanticElement) {
+ return (View) lastNotationElement;
+ }
+
+ if (notationElement != null) {
+ lastNotationElement = notationElement;
+ }
+ }
+
+ return (View) lastNotationElement;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/listener/CustomStyleListener.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/listener/CustomStyleListener.java
index d9a2137ae98..2ebceed7ddc 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/listener/CustomStyleListener.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/listener/CustomStyleListener.java
@@ -1,133 +1,133 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.listener;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.core.databinding.observable.IChangeListener;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.common.notify.Notifier;
-import org.eclipse.emf.common.notify.impl.AdapterImpl;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.EStructuralFeature;
-import org.eclipse.gmf.runtime.notation.NamedStyle;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * A Listener for GMF CustomStyle changes
- *
- * @author Camille Letavernier
- */
-public class CustomStyleListener extends AdapterImpl {
-
- private final Collection<String> styleNames;
-
- // FIXME: Use a specific listener
- private final IChangeListener listener;
-
- private boolean disposed;
-
- private final EStructuralFeature listenedFeature;
-
- public CustomStyleListener(View source, EStructuralFeature listenedFeature, IChangeListener listener, String styleName) {
- this(source, listenedFeature, listener, Collections.singleton(styleName));
- }
-
- public CustomStyleListener(View source, IChangeListener listener, Collection<String> styleNames) {
- this(source, null, listener, styleNames);
- }
-
- public CustomStyleListener(View source, EStructuralFeature listenedFeature, IChangeListener listener, Collection<String> styleNames) {
- this.styleNames = styleNames;
- this.listener = listener;
- this.listenedFeature = listenedFeature;
- for (Object styleObject : source.getStyles()) {
- if (styleObject instanceof NamedStyle) {
- NamedStyle style = (NamedStyle) styleObject;
- if (styleNames.contains(style.getName())) {
- // FIXME: If a style's name is changed, we won't be notified. We should probably listen on all styles
- // FIXME: If the style is an EObjectValueStyle or EObjectListValueStyle, we should also listen on values
- style.eAdapters().add(this);
- }
- }
- }
- }
-
- @Override
- public void notifyChanged(Notification notification) {
- // The listener has been disposed: remove it from the notifier
- // and ignore the notification
- if (disposed) {
- ((Notifier) notification.getNotifier()).eAdapters().remove(this);
- return;
- }
-
- // A style object has been added or removed on the notifier: begin or
- // stop listening the notifier, and notify our listener (if needed)
- if (notification.getFeature() == NotationPackage.eINSTANCE.getView_Styles()) {
- switch (notification.getEventType()) {
- case Notification.ADD:
- handleAdd((EObject) notification.getNewValue());
- break;
- case Notification.ADD_MANY:
- for (Object object : (List<?>) notification.getNewValue()) {
- handleAdd((EObject) object);
- }
- break;
- case Notification.REMOVE:
- handleRemove((EObject) notification.getOldValue());
- break;
- case Notification.REMOVE_MANY:
- for (Object object : (List<?>) notification.getOldValue()) {
- handleRemove((EObject) object);
- }
- break;
- }
- return;
- }
-
- // If the change occurred on one style instance, notify the listener (If needed)
- if (notification.getFeature() == listenedFeature || listenedFeature == null) {
- if (!notification.isTouch()) {
- handleChange(notification.getNotifier());
- }
- }
- }
-
- private void handleRemove(EObject oldValue) {
- oldValue.eAdapters().remove(this);
- handleChange(oldValue);
- }
-
- private void handleAdd(EObject newValue) {
- newValue.eAdapters().add(this);
- handleChange(newValue);
- }
-
- private void handleChange(Object value) {
- if (value instanceof NamedStyle) {
- if (styleNames.contains(((NamedStyle) value).getName())) {
- // FIXME: Build a usable event, so that listeners don't need to reset
- // the whole CSS Engine/refresh the whole diagram each time.
- listener.handleChange(null);
- }
- }
- }
-
- public void dispose() {
- this.disposed = true;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.listener;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.databinding.observable.IChangeListener;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.common.notify.Notifier;
+import org.eclipse.emf.common.notify.impl.AdapterImpl;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.gmf.runtime.notation.NamedStyle;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * A Listener for GMF CustomStyle changes
+ *
+ * @author Camille Letavernier
+ */
+public class CustomStyleListener extends AdapterImpl {
+
+ private final Collection<String> styleNames;
+
+ // FIXME: Use a specific listener
+ private final IChangeListener listener;
+
+ private boolean disposed;
+
+ private final EStructuralFeature listenedFeature;
+
+ public CustomStyleListener(View source, EStructuralFeature listenedFeature, IChangeListener listener, String styleName) {
+ this(source, listenedFeature, listener, Collections.singleton(styleName));
+ }
+
+ public CustomStyleListener(View source, IChangeListener listener, Collection<String> styleNames) {
+ this(source, null, listener, styleNames);
+ }
+
+ public CustomStyleListener(View source, EStructuralFeature listenedFeature, IChangeListener listener, Collection<String> styleNames) {
+ this.styleNames = styleNames;
+ this.listener = listener;
+ this.listenedFeature = listenedFeature;
+ for (Object styleObject : source.getStyles()) {
+ if (styleObject instanceof NamedStyle) {
+ NamedStyle style = (NamedStyle) styleObject;
+ if (styleNames.contains(style.getName())) {
+ // FIXME: If a style's name is changed, we won't be notified. We should probably listen on all styles
+ // FIXME: If the style is an EObjectValueStyle or EObjectListValueStyle, we should also listen on values
+ style.eAdapters().add(this);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void notifyChanged(Notification notification) {
+ // The listener has been disposed: remove it from the notifier
+ // and ignore the notification
+ if (disposed) {
+ ((Notifier) notification.getNotifier()).eAdapters().remove(this);
+ return;
+ }
+
+ // A style object has been added or removed on the notifier: begin or
+ // stop listening the notifier, and notify our listener (if needed)
+ if (notification.getFeature() == NotationPackage.eINSTANCE.getView_Styles()) {
+ switch (notification.getEventType()) {
+ case Notification.ADD:
+ handleAdd((EObject) notification.getNewValue());
+ break;
+ case Notification.ADD_MANY:
+ for (Object object : (List<?>) notification.getNewValue()) {
+ handleAdd((EObject) object);
+ }
+ break;
+ case Notification.REMOVE:
+ handleRemove((EObject) notification.getOldValue());
+ break;
+ case Notification.REMOVE_MANY:
+ for (Object object : (List<?>) notification.getOldValue()) {
+ handleRemove((EObject) object);
+ }
+ break;
+ }
+ return;
+ }
+
+ // If the change occurred on one style instance, notify the listener (If needed)
+ if (notification.getFeature() == listenedFeature || listenedFeature == null) {
+ if (!notification.isTouch()) {
+ handleChange(notification.getNotifier());
+ }
+ }
+ }
+
+ private void handleRemove(EObject oldValue) {
+ oldValue.eAdapters().remove(this);
+ handleChange(oldValue);
+ }
+
+ private void handleAdd(EObject newValue) {
+ newValue.eAdapters().add(this);
+ handleChange(newValue);
+ }
+
+ private void handleChange(Object value) {
+ if (value instanceof NamedStyle) {
+ if (styleNames.contains(((NamedStyle) value).getName())) {
+ // FIXME: Build a usable event, so that listeners don't need to reset
+ // the whole CSS Engine/refresh the whole diagram each time.
+ listener.handleChange(null);
+ }
+ }
+ }
+
+ public void dispose() {
+ this.disposed = true;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferenceInitializer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferenceInitializer.java
index 12919ef25a9..5923a582d7d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferenceInitializer.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferenceInitializer.java
@@ -1,27 +1,27 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
-
-import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-
-public class ConnectionToolPreferenceInitializer extends AbstractPreferenceInitializer {
-
- @Override
- public void initializeDefaultPreferences() {
- IPreferenceStore store = Activator.getInstance().getPreferenceStore();
- store.setDefault(ConnectionToolPreferences.DRAW_CONNECTION_MODE, ConnectionToolPreferences.TWO_CLICKS);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
+
+import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+
+public class ConnectionToolPreferenceInitializer extends AbstractPreferenceInitializer {
+
+ @Override
+ public void initializeDefaultPreferences() {
+ IPreferenceStore store = Activator.getInstance().getPreferenceStore();
+ store.setDefault(ConnectionToolPreferences.DRAW_CONNECTION_MODE, ConnectionToolPreferences.TWO_CLICKS);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferencePage.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferencePage.java
index b99058459eb..334a5184a65 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferencePage.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferencePage.java
@@ -1,35 +1,35 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
-
-import org.eclipse.jface.preference.ComboFieldEditor;
-import org.eclipse.jface.preference.FieldEditorPreferencePage;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-
-
-public class ConnectionToolPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
-
- @Override
- public void init(IWorkbench workbench) {
- setPreferenceStore(Activator.getInstance().getPreferenceStore());
- }
-
- @Override
- protected void createFieldEditors() {
- String[][] values = { { "Single click", ConnectionToolPreferences.SINGLE_CLICK }, { "Two clicks", ConnectionToolPreferences.TWO_CLICKS } };
- ComboFieldEditor fieldEditor = new ComboFieldEditor(ConnectionToolPreferences.DRAW_CONNECTION_MODE, "Draw links mode", values, getFieldEditorParent());
- addField(fieldEditor);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
+
+import org.eclipse.jface.preference.ComboFieldEditor;
+import org.eclipse.jface.preference.FieldEditorPreferencePage;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+
+public class ConnectionToolPreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
+
+ @Override
+ public void init(IWorkbench workbench) {
+ setPreferenceStore(Activator.getInstance().getPreferenceStore());
+ }
+
+ @Override
+ protected void createFieldEditors() {
+ String[][] values = { { "Single click", ConnectionToolPreferences.SINGLE_CLICK }, { "Two clicks", ConnectionToolPreferences.TWO_CLICKS } };
+ ComboFieldEditor fieldEditor = new ComboFieldEditor(ConnectionToolPreferences.DRAW_CONNECTION_MODE, "Draw links mode", values, getFieldEditorParent());
+ addField(fieldEditor);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferences.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferences.java
index 761fe44cddc..750fd38a807 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferences.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/preferences/ConnectionToolPreferences.java
@@ -1,36 +1,36 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-
-public class ConnectionToolPreferences {
-
- public static final String DRAW_CONNECTION_MODE = "drawConnectionMode";
-
- public static final String SINGLE_CLICK = "singleClick";
-
- public static final String TWO_CLICKS = "twoClicks";
-
- private ConnectionToolPreferences() {
- }
-
- public boolean isInSingleClickMode() {
- return SINGLE_CLICK.equals(preferences.getString(DRAW_CONNECTION_MODE));
- }
-
- private IPreferenceStore preferences = Activator.getInstance().getPreferenceStore();
-
- public static final ConnectionToolPreferences instance = new ConnectionToolPreferences();
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.preferences;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+
+public class ConnectionToolPreferences {
+
+ public static final String DRAW_CONNECTION_MODE = "drawConnectionMode";
+
+ public static final String SINGLE_CLICK = "singleClick";
+
+ public static final String TWO_CLICKS = "twoClicks";
+
+ private ConnectionToolPreferences() {
+ }
+
+ public boolean isInSingleClickMode() {
+ return SINGLE_CLICK.equals(preferences.getString(DRAW_CONNECTION_MODE));
+ }
+
+ private IPreferenceStore preferences = Activator.getInstance().getPreferenceStore();
+
+ public static final ConnectionToolPreferences instance = new ConnectionToolPreferences();
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractShapeCompartmentEditPartProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractShapeCompartmentEditPartProvider.java
index d0ba42f17c9..59aff66b123 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractShapeCompartmentEditPartProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractShapeCompartmentEditPartProvider.java
@@ -1,85 +1,85 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ShapeDisplayCompartmentEditPart;
-
-/**
- * provides editpart to display shapes in compartment.
- */
-public abstract class AbstractShapeCompartmentEditPartProvider extends AbstractEditPartProvider {
-
- /** Map containing node view types supported by this provider */
- protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>();
-
- /** Map containing edge view types supported by this provider */
- protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>();
-
- /** Default constructor */
- public AbstractShapeCompartmentEditPartProvider() {
- super();
- nodeMap.put(IShapeCompartmentEditPart.VIEW_TYPE, ShapeDisplayCompartmentEditPart.class);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean provides(IOperation operation) {
- if (operation instanceof IEditPartOperation) {
- View newView = ((IEditPartOperation) operation).getView();
- if (newView == null) {
- return false;
- }
-
- String graphicalType = newView.getType();
-
- if ((newView instanceof Node) && (!nodeMap.containsKey(graphicalType))) {
- return false;
- }
-
- if ((newView instanceof Edge) && (!edgeMap.containsKey(graphicalType))) {
- return false;
- }
- }
-
- return super.provides(operation);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Class<?> getNodeEditPartClass(View view) {
- return nodeMap.get(view.getType());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected Class<?> getEdgeEditPartClass(View view) {
- return edgeMap.get(view.getType());
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.IShapeCompartmentEditPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpart.ShapeDisplayCompartmentEditPart;
+
+/**
+ * provides editpart to display shapes in compartment.
+ */
+public abstract class AbstractShapeCompartmentEditPartProvider extends AbstractEditPartProvider {
+
+ /** Map containing node view types supported by this provider */
+ protected Map<String, Class<?>> nodeMap = new HashMap<String, Class<?>>();
+
+ /** Map containing edge view types supported by this provider */
+ protected Map<String, Class<?>> edgeMap = new HashMap<String, Class<?>>();
+
+ /** Default constructor */
+ public AbstractShapeCompartmentEditPartProvider() {
+ super();
+ nodeMap.put(IShapeCompartmentEditPart.VIEW_TYPE, ShapeDisplayCompartmentEditPart.class);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean provides(IOperation operation) {
+ if (operation instanceof IEditPartOperation) {
+ View newView = ((IEditPartOperation) operation).getView();
+ if (newView == null) {
+ return false;
+ }
+
+ String graphicalType = newView.getType();
+
+ if ((newView instanceof Node) && (!nodeMap.containsKey(graphicalType))) {
+ return false;
+ }
+
+ if ((newView instanceof Edge) && (!edgeMap.containsKey(graphicalType))) {
+ return false;
+ }
+ }
+
+ return super.provides(operation);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Class<?> getNodeEditPartClass(View view) {
+ return nodeMap.get(view.getType());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Class<?> getEdgeEditPartClass(View view) {
+ return edgeMap.get(view.getType());
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractViewProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractViewProvider.java
index 2d7c5b48387..df7a8ac6517 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractViewProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/AbstractViewProvider.java
@@ -1,322 +1,322 @@
-/******************************************************************************
- * Copyright (c) 2002, 2010 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
- *
- * CEA LIST - createNode and createEdge final statement removed
- * in order to provide different implementation in subclasses.
- * The original class is {@link AbstractViewProvider}.
- *
- ****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-
-import org.eclipse.core.runtime.IAdaptable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.emf.ecore.EClass;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.util.Log;
-import org.eclipse.gmf.runtime.diagram.core.internal.DiagramPlugin;
-import org.eclipse.gmf.runtime.diagram.core.internal.DiagramStatusCodes;
-import org.eclipse.gmf.runtime.diagram.core.internal.l10n.DiagramCoreMessages;
-import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
-import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
-import org.eclipse.gmf.runtime.diagram.core.services.view.CreateEdgeViewOperation;
-import org.eclipse.gmf.runtime.diagram.core.services.view.CreateNodeViewOperation;
-import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewForKindOperation;
-import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewOperation;
-import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
-import org.eclipse.gmf.runtime.emf.type.core.IElementType;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.Edge;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.osgi.util.NLS;
-
-/**
- * Implements of the <code>IViewProvider</code> interface. This
- * implementations invokes the appropriate factory method by inspecting the
- * supplied operation and provides the actual view creation functionality.
- */
-public class AbstractViewProvider extends AbstractProvider implements IViewProvider {
-
- private static String viewCreationMethodName = "createView"; //$NON-NLS-1$
-
- private static String diagramCreationMethodName = "createDiagram"; //$NON-NLS-1$
-
- static protected class ClassToCreationMethodMap extends HashMap<Class<?>, Method> {
-
- static final long serialVersionUID = 1;
-
- public void addMethod(Class<?> clazz, Method method) {
- if (get(clazz) == null) {
- put(clazz, method);
- }
- }
-
- public Method getCreationMethod(Class<?> clazz) {
- return get(clazz);
- }
- }
-
- public static final ClassToCreationMethodMap classToCreateMethod = new ClassToCreationMethodMap();
-
- /**
- * Determines whether this view provider can provide for the required
- * operation It inspects the type of view operation and calls the
- * corresponding <code>provides</code> method.
- *
- * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(IOperation)
- */
- @Override
- public final boolean provides(IOperation operation) {
- /* if this is the CreateViewForKindOperation operation */
- if (operation instanceof CreateViewForKindOperation) {
- return provides((CreateViewForKindOperation) operation);
- }
- /* Make sure it is a view operation */
- assert operation instanceof CreateViewOperation : "operation is not CreateViewOperation in AbstractViewProvider";//$NON-NLS-1$
- /* call the specific provides method */
- if (operation instanceof CreateDiagramViewOperation) {
- return provides((CreateDiagramViewOperation) operation);
- } else if (operation instanceof CreateEdgeViewOperation) {
- return provides((CreateEdgeViewOperation) operation);
- } else if (operation instanceof CreateNodeViewOperation) {
- return provides((CreateNodeViewOperation) operation);
- }
- return false;
- }
-
- @Override
- public final Diagram createDiagram(IAdaptable contextElement, String diagramKind, PreferencesHint preferencesHint) {
- return (Diagram) createNewView(getDiagramViewClass(contextElement, diagramKind), new Object[] { contextElement, diagramKind, preferencesHint });
- }
-
- // Papyrus - final statement removed
- @Override
- public Edge createEdge(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
- return (Edge) createNewView(getEdgeViewClass(semanticAdapter, containerView, semanticHint), new Object[] { semanticAdapter, containerView, semanticHint, new Integer(index), Boolean.valueOf(persisted), preferencesHint });
- }
-
- // Papyrus - final statement removed
- @Override
- public Node createNode(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
- return (Node) createNewView(getNodeViewClass(semanticAdapter, containerView, semanticHint), new Object[] { semanticAdapter, containerView, semanticHint, new Integer(index), Boolean.valueOf(persisted), preferencesHint });
- }
-
- /**
- * Determines whether this provider can provide for the specified view
- * creation operation
- *
- * @param operation
- * Contains a semantic kind and a containerView
- * @return boolean
- */
- protected boolean provides(CreateViewForKindOperation op) {
- if (op.getViewKind() == Node.class) {
- return getNodeViewClass(op.getSemanticAdapter(), op.getContainerView(), op.getSemanticHint()) != null;
- }
- if (op.getViewKind() == Edge.class) {
- return getEdgeViewClass(op.getSemanticAdapter(), op.getContainerView(), op.getSemanticHint()) != null;
- }
- return true;
- }
-
- /**
- * Determines whether this provider can provide for the specified diagram
- * view operation
- *
- * @param operation
- * @return boolean
- */
- protected boolean provides(CreateDiagramViewOperation operation) {
- return getDiagramViewClass(operation.getSemanticAdapter(), operation.getSemanticHint()) != null;
- }
-
- /**
- * Determines whether this provider can provide for the specified edge view
- * operation
- *
- * @param operation
- * @return boolean
- */
- protected boolean provides(CreateEdgeViewOperation operation) {
- return (getEdgeViewClass(operation.getSemanticAdapter(), operation.getContainerView(), operation.getSemanticHint()) != null);
- }
-
- /**
- * Determines whether this provider can provide for the specified node view
- * operation
- *
- * @param operation
- * @return boolean
- */
- protected boolean provides(CreateNodeViewOperation operation) {
- return (getNodeViewClass(operation.getSemanticAdapter(), operation.getContainerView(), operation.getSemanticHint()) != null);
- }
-
- /**
- * Returns the diagram view class to instantiate based on the passed params
- *
- * @param semanticAdapter
- * TODO
- * @param semanticAdapter
- * @return Class
- */
- protected Class<?> getDiagramViewClass(IAdaptable semanticAdapter, String diagramKind) {
- return null;
- }
-
- /**
- * Returns the edge view class to instantiate based on the passed params
- *
- * @param semanticAdapter
- * @param containerView
- * @param semanticHint
- * @return Class
- */
- protected Class<?> getEdgeViewClass(IAdaptable semanticAdapter, View containerView, String semanticHint) {
- return null;
- }
-
- /**
- * Returns the node view class to instantiate based on the passed params
- *
- * @param semanticAdapter
- * @param containerView
- * @param semanticHint
- * @return Class
- */
- protected Class<?> getNodeViewClass(IAdaptable semanticAdapter, View containerView, String semanticHint) {
- return null;
- }
-
- /**
- * creates a view instance via reflection.
- *
- * @param constructorParams
- * the view's constructor parameters.
- */
- private View createNewView(Class<?> viewClass, Object[] constructorParams) {
- try {
- assert null != viewClass : "Null viewClass in AbstractProvider";//$NON-NLS-1$
- assert null != constructorParams : "Null constructorParams in AbstractProvider";//$NON-NLS-1$
- Constructor<?> constructor = getFactoryConstructor(viewClass);
- if (constructor == null) {
- Log.error(DiagramPlugin.getInstance(), DiagramStatusCodes.SERVICE_FAILURE, "View (" + viewClass + ") is missing a proper creation Factory"); //$NON-NLS-1$//$NON-NLS-2$
- return null;
- }
- Object factory = constructor.newInstance(new Object[] {});
- Method method = getCreationMethod(viewClass, constructorParams);
- if (method == null) {
- Log.error(DiagramPlugin.getInstance(), DiagramStatusCodes.SERVICE_FAILURE, "View (" + viewClass + ") is missing a proper creation Factory"); //$NON-NLS-1$//$NON-NLS-2$
- return null;
- }
- return (View) method.invoke(factory, constructorParams);
- } catch (Throwable e) {
- String eMsg = NLS.bind(DiagramCoreMessages.AbstractViewProvider_create_view_failed_ERROR_, viewClass.getName());
- Log.warning(DiagramPlugin.getInstance(), IStatus.WARNING, eMsg, e);
- return null;
- }
- }
-
- private Constructor<?> getFactoryConstructor(Class<?> viewClass) {
- if (viewClass != null) {
- Constructor<?>[] ctors = viewClass.getConstructors();
- for (int i = 0; i < ctors.length; i++) {
- if (ctors[i].getParameterTypes().length == 0) {
- return ctors[i];
- }
- }
- }
- return null;
- }
-
- /** Return the <i>creation</i> constructor for the cached view class. */
- private Method getCreationMethod(Class<?> viewClass, Object[] params) {
- if (viewClass != null) {
- Method method = classToCreateMethod.getCreationMethod(viewClass);
- if (method != null) {
- return method;
- }
- Method[] methods = viewClass.getMethods();
- for (int i = 0; i < methods.length; i++) {
- method = methods[i];
- String methodName = method.getName();
- if (methodName.equals(viewCreationMethodName) || methodName.equals(diagramCreationMethodName)) {
- classToCreateMethod.addMethod(viewClass, method);
- return method;
- }
- }
- }
- return null;
- }
-
- /**
- * Returns the EClass associated with the semantic adapter
- *
- * @param semanticAdapter
- * @return EClass
- */
- protected EClass getSemanticEClass(IAdaptable semanticAdapter) {
- if (semanticAdapter == null) {
- return null;
- }
- EObject eObject = semanticAdapter.getAdapter(EObject.class);
- if (eObject != null) {
- return EMFCoreUtil.getProxyClass(eObject);
- }
- IElementType type = semanticAdapter.getAdapter(IElementType.class);
- if (type != null) {
- return type.getEClass();
- }
- return null;
- }
-
- /**
- * Returns the semantic element associated with the semantic adapter
- *
- * @param semanticAdapter
- * @return EClass
- */
- protected EObject getSemanticElement(IAdaptable semanticAdapter) {
- if (semanticAdapter == null) {
- return null;
- }
- EObject eObject = semanticAdapter.getAdapter(EObject.class);
- if (eObject != null) {
- return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
- }
- return null;
- }
-
- /**
- * Returns the semantic element associated with the semantic adapter
- *
- * @param semanticAdapter
- * @return EClass
- */
- protected EObject getSemanticElement(IAdaptable semanticAdapter, TransactionalEditingDomain domain) {
- if (semanticAdapter == null) {
- return null;
- }
- EObject eObject = semanticAdapter.getAdapter(EObject.class);
- if (eObject != null) {
- return EMFCoreUtil.resolve(domain, eObject);
- }
- return null;
- }
-}
+/******************************************************************************
+ * Copyright (c) 2002, 2010 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
+ *
+ * CEA LIST - createNode and createEdge final statement removed
+ * in order to provide different implementation in subclasses.
+ * The original class is {@link AbstractViewProvider}.
+ *
+ ****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.util.Log;
+import org.eclipse.gmf.runtime.diagram.core.internal.DiagramPlugin;
+import org.eclipse.gmf.runtime.diagram.core.internal.DiagramStatusCodes;
+import org.eclipse.gmf.runtime.diagram.core.internal.l10n.DiagramCoreMessages;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.core.providers.IViewProvider;
+import org.eclipse.gmf.runtime.diagram.core.services.view.CreateDiagramViewOperation;
+import org.eclipse.gmf.runtime.diagram.core.services.view.CreateEdgeViewOperation;
+import org.eclipse.gmf.runtime.diagram.core.services.view.CreateNodeViewOperation;
+import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewForKindOperation;
+import org.eclipse.gmf.runtime.diagram.core.services.view.CreateViewOperation;
+import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
+import org.eclipse.gmf.runtime.emf.type.core.IElementType;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.Edge;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Implements of the <code>IViewProvider</code> interface. This
+ * implementations invokes the appropriate factory method by inspecting the
+ * supplied operation and provides the actual view creation functionality.
+ */
+public class AbstractViewProvider extends AbstractProvider implements IViewProvider {
+
+ private static String viewCreationMethodName = "createView"; //$NON-NLS-1$
+
+ private static String diagramCreationMethodName = "createDiagram"; //$NON-NLS-1$
+
+ static protected class ClassToCreationMethodMap extends HashMap<Class<?>, Method> {
+
+ static final long serialVersionUID = 1;
+
+ public void addMethod(Class<?> clazz, Method method) {
+ if (get(clazz) == null) {
+ put(clazz, method);
+ }
+ }
+
+ public Method getCreationMethod(Class<?> clazz) {
+ return get(clazz);
+ }
+ }
+
+ public static final ClassToCreationMethodMap classToCreateMethod = new ClassToCreationMethodMap();
+
+ /**
+ * Determines whether this view provider can provide for the required
+ * operation It inspects the type of view operation and calls the
+ * corresponding <code>provides</code> method.
+ *
+ * @see org.eclipse.gmf.runtime.common.core.service.IProvider#provides(IOperation)
+ */
+ @Override
+ public final boolean provides(IOperation operation) {
+ /* if this is the CreateViewForKindOperation operation */
+ if (operation instanceof CreateViewForKindOperation) {
+ return provides((CreateViewForKindOperation) operation);
+ }
+ /* Make sure it is a view operation */
+ assert operation instanceof CreateViewOperation : "operation is not CreateViewOperation in AbstractViewProvider";//$NON-NLS-1$
+ /* call the specific provides method */
+ if (operation instanceof CreateDiagramViewOperation) {
+ return provides((CreateDiagramViewOperation) operation);
+ } else if (operation instanceof CreateEdgeViewOperation) {
+ return provides((CreateEdgeViewOperation) operation);
+ } else if (operation instanceof CreateNodeViewOperation) {
+ return provides((CreateNodeViewOperation) operation);
+ }
+ return false;
+ }
+
+ @Override
+ public final Diagram createDiagram(IAdaptable contextElement, String diagramKind, PreferencesHint preferencesHint) {
+ return (Diagram) createNewView(getDiagramViewClass(contextElement, diagramKind), new Object[] { contextElement, diagramKind, preferencesHint });
+ }
+
+ // Papyrus - final statement removed
+ @Override
+ public Edge createEdge(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
+ return (Edge) createNewView(getEdgeViewClass(semanticAdapter, containerView, semanticHint), new Object[] { semanticAdapter, containerView, semanticHint, new Integer(index), Boolean.valueOf(persisted), preferencesHint });
+ }
+
+ // Papyrus - final statement removed
+ @Override
+ public Node createNode(IAdaptable semanticAdapter, View containerView, String semanticHint, int index, boolean persisted, PreferencesHint preferencesHint) {
+ return (Node) createNewView(getNodeViewClass(semanticAdapter, containerView, semanticHint), new Object[] { semanticAdapter, containerView, semanticHint, new Integer(index), Boolean.valueOf(persisted), preferencesHint });
+ }
+
+ /**
+ * Determines whether this provider can provide for the specified view
+ * creation operation
+ *
+ * @param operation
+ * Contains a semantic kind and a containerView
+ * @return boolean
+ */
+ protected boolean provides(CreateViewForKindOperation op) {
+ if (op.getViewKind() == Node.class) {
+ return getNodeViewClass(op.getSemanticAdapter(), op.getContainerView(), op.getSemanticHint()) != null;
+ }
+ if (op.getViewKind() == Edge.class) {
+ return getEdgeViewClass(op.getSemanticAdapter(), op.getContainerView(), op.getSemanticHint()) != null;
+ }
+ return true;
+ }
+
+ /**
+ * Determines whether this provider can provide for the specified diagram
+ * view operation
+ *
+ * @param operation
+ * @return boolean
+ */
+ protected boolean provides(CreateDiagramViewOperation operation) {
+ return getDiagramViewClass(operation.getSemanticAdapter(), operation.getSemanticHint()) != null;
+ }
+
+ /**
+ * Determines whether this provider can provide for the specified edge view
+ * operation
+ *
+ * @param operation
+ * @return boolean
+ */
+ protected boolean provides(CreateEdgeViewOperation operation) {
+ return (getEdgeViewClass(operation.getSemanticAdapter(), operation.getContainerView(), operation.getSemanticHint()) != null);
+ }
+
+ /**
+ * Determines whether this provider can provide for the specified node view
+ * operation
+ *
+ * @param operation
+ * @return boolean
+ */
+ protected boolean provides(CreateNodeViewOperation operation) {
+ return (getNodeViewClass(operation.getSemanticAdapter(), operation.getContainerView(), operation.getSemanticHint()) != null);
+ }
+
+ /**
+ * Returns the diagram view class to instantiate based on the passed params
+ *
+ * @param semanticAdapter
+ * TODO
+ * @param semanticAdapter
+ * @return Class
+ */
+ protected Class<?> getDiagramViewClass(IAdaptable semanticAdapter, String diagramKind) {
+ return null;
+ }
+
+ /**
+ * Returns the edge view class to instantiate based on the passed params
+ *
+ * @param semanticAdapter
+ * @param containerView
+ * @param semanticHint
+ * @return Class
+ */
+ protected Class<?> getEdgeViewClass(IAdaptable semanticAdapter, View containerView, String semanticHint) {
+ return null;
+ }
+
+ /**
+ * Returns the node view class to instantiate based on the passed params
+ *
+ * @param semanticAdapter
+ * @param containerView
+ * @param semanticHint
+ * @return Class
+ */
+ protected Class<?> getNodeViewClass(IAdaptable semanticAdapter, View containerView, String semanticHint) {
+ return null;
+ }
+
+ /**
+ * creates a view instance via reflection.
+ *
+ * @param constructorParams
+ * the view's constructor parameters.
+ */
+ private View createNewView(Class<?> viewClass, Object[] constructorParams) {
+ try {
+ assert null != viewClass : "Null viewClass in AbstractProvider";//$NON-NLS-1$
+ assert null != constructorParams : "Null constructorParams in AbstractProvider";//$NON-NLS-1$
+ Constructor<?> constructor = getFactoryConstructor(viewClass);
+ if (constructor == null) {
+ Log.error(DiagramPlugin.getInstance(), DiagramStatusCodes.SERVICE_FAILURE, "View (" + viewClass + ") is missing a proper creation Factory"); //$NON-NLS-1$//$NON-NLS-2$
+ return null;
+ }
+ Object factory = constructor.newInstance(new Object[] {});
+ Method method = getCreationMethod(viewClass, constructorParams);
+ if (method == null) {
+ Log.error(DiagramPlugin.getInstance(), DiagramStatusCodes.SERVICE_FAILURE, "View (" + viewClass + ") is missing a proper creation Factory"); //$NON-NLS-1$//$NON-NLS-2$
+ return null;
+ }
+ return (View) method.invoke(factory, constructorParams);
+ } catch (Throwable e) {
+ String eMsg = NLS.bind(DiagramCoreMessages.AbstractViewProvider_create_view_failed_ERROR_, viewClass.getName());
+ Log.warning(DiagramPlugin.getInstance(), IStatus.WARNING, eMsg, e);
+ return null;
+ }
+ }
+
+ private Constructor<?> getFactoryConstructor(Class<?> viewClass) {
+ if (viewClass != null) {
+ Constructor<?>[] ctors = viewClass.getConstructors();
+ for (int i = 0; i < ctors.length; i++) {
+ if (ctors[i].getParameterTypes().length == 0) {
+ return ctors[i];
+ }
+ }
+ }
+ return null;
+ }
+
+ /** Return the <i>creation</i> constructor for the cached view class. */
+ private Method getCreationMethod(Class<?> viewClass, Object[] params) {
+ if (viewClass != null) {
+ Method method = classToCreateMethod.getCreationMethod(viewClass);
+ if (method != null) {
+ return method;
+ }
+ Method[] methods = viewClass.getMethods();
+ for (int i = 0; i < methods.length; i++) {
+ method = methods[i];
+ String methodName = method.getName();
+ if (methodName.equals(viewCreationMethodName) || methodName.equals(diagramCreationMethodName)) {
+ classToCreateMethod.addMethod(viewClass, method);
+ return method;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the EClass associated with the semantic adapter
+ *
+ * @param semanticAdapter
+ * @return EClass
+ */
+ protected EClass getSemanticEClass(IAdaptable semanticAdapter) {
+ if (semanticAdapter == null) {
+ return null;
+ }
+ EObject eObject = semanticAdapter.getAdapter(EObject.class);
+ if (eObject != null) {
+ return EMFCoreUtil.getProxyClass(eObject);
+ }
+ IElementType type = semanticAdapter.getAdapter(IElementType.class);
+ if (type != null) {
+ return type.getEClass();
+ }
+ return null;
+ }
+
+ /**
+ * Returns the semantic element associated with the semantic adapter
+ *
+ * @param semanticAdapter
+ * @return EClass
+ */
+ protected EObject getSemanticElement(IAdaptable semanticAdapter) {
+ if (semanticAdapter == null) {
+ return null;
+ }
+ EObject eObject = semanticAdapter.getAdapter(EObject.class);
+ if (eObject != null) {
+ return EMFCoreUtil.resolve(TransactionUtil.getEditingDomain(eObject), eObject);
+ }
+ return null;
+ }
+
+ /**
+ * Returns the semantic element associated with the semantic adapter
+ *
+ * @param semanticAdapter
+ * @return EClass
+ */
+ protected EObject getSemanticElement(IAdaptable semanticAdapter, TransactionalEditingDomain domain) {
+ if (semanticAdapter == null) {
+ return null;
+ }
+ EObject eObject = semanticAdapter.getAdapter(EObject.class);
+ if (eObject != null) {
+ return EMFCoreUtil.resolve(domain, eObject);
+ }
+ return null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java
index c9a3f7e8d5e..d3d717f2201 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/CustomEditPolicyProvider.java
@@ -1,101 +1,101 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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:
- * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.emf.edit.domain.EditingDomain;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPolicy;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.HighlightEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
-
-/**
- * this is an editpolicy provider in charge to install a policy to navigate between diagrams and elements
- *
- */
-public class CustomEditPolicyProvider implements IEditPolicyProvider {
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void addProviderChangeListener(IProviderChangeListener listener) {
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void createEditPolicies(final EditPart editPart) {
- installEditPolicy(editPart, new HighlightEditPolicy(), HighlightEditPolicy.HIGHLIGHT_ROLE);
- }
-
- /**
- * Safely install a EditPolicy, if the editpolicy with given role is existed in editpart, ignore it.
- *
- * @param editPart
- * @param editPolicy
- * @param role
- */
- private void installEditPolicy(EditPart editPart, EditPolicy editPolicy, String role) {
- if (editPart == null || editPolicy == null) {
- return;
- }
- EditPolicy myEditPolicy = editPart.getEditPolicy(role);
- if (myEditPolicy == null) {
- editPart.installEditPolicy(role, editPolicy);
- }
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public boolean provides(IOperation operation) {
- CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
- try {
- EditPart editPart = epOperation.getEditPart();
- if (!(editPart instanceof GraphicalEditPart)) {
- return false;
- }
-
- EditingDomain domain = EMFHelper.resolveEditingDomain(editPart);
- if (domain == null) {
- return false;
- }
-
- ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(epOperation.getEditPart());
- return registry != null;
- } catch (ServiceException e) {
- return false;
- }
-
- }
-
- /**
- *
- * {@inheritDoc}
- */
- @Override
- public void removeProviderChangeListener(IProviderChangeListener listener) {
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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:
+ * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.emf.edit.domain.EditingDomain;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPolicy;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProviderChangeListener;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.HighlightEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+
+/**
+ * this is an editpolicy provider in charge to install a policy to navigate between diagrams and elements
+ *
+ */
+public class CustomEditPolicyProvider implements IEditPolicyProvider {
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void addProviderChangeListener(IProviderChangeListener listener) {
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void createEditPolicies(final EditPart editPart) {
+ installEditPolicy(editPart, new HighlightEditPolicy(), HighlightEditPolicy.HIGHLIGHT_ROLE);
+ }
+
+ /**
+ * Safely install a EditPolicy, if the editpolicy with given role is existed in editpart, ignore it.
+ *
+ * @param editPart
+ * @param editPolicy
+ * @param role
+ */
+ private void installEditPolicy(EditPart editPart, EditPolicy editPolicy, String role) {
+ if (editPart == null || editPolicy == null) {
+ return;
+ }
+ EditPolicy myEditPolicy = editPart.getEditPolicy(role);
+ if (myEditPolicy == null) {
+ editPart.installEditPolicy(role, editPolicy);
+ }
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean provides(IOperation operation) {
+ CreateEditPoliciesOperation epOperation = (CreateEditPoliciesOperation) operation;
+ try {
+ EditPart editPart = epOperation.getEditPart();
+ if (!(editPart instanceof GraphicalEditPart)) {
+ return false;
+ }
+
+ EditingDomain domain = EMFHelper.resolveEditingDomain(editPart);
+ if (domain == null) {
+ return false;
+ }
+
+ ServicesRegistry registry = ServiceUtilsForEditPart.getInstance().getServiceRegistry(epOperation.getEditPart());
+ return registry != null;
+ } catch (ServiceException e) {
+ return false;
+ }
+
+ }
+
+ /**
+ *
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeProviderChangeListener(IProviderChangeListener listener) {
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java
index 6c7f760ce35..39dd468c4b0 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ExternalReferenceEditPolicyProvider.java
@@ -1,55 +1,55 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalReferenceEditPolicy;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
-
-/**
- * The EditPolicyProvider for {@link ExternalReferenceEditPolicy} It provides an {@link ExternalReferenceEditPolicy} for Papyrus edit parts, when the
- * ServicesRegistry is available
- * This edit policy in only installed on Shapes (Graphical Edges are typically owned by the Diagram, which makes it difficult
- * to determine whether they are imported or not)
- *
- * @author Camille Letavernier
- */
-public class ExternalReferenceEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
-
- @Override
- public boolean provides(IOperation operation) {
- if (operation instanceof CreateEditPoliciesOperation) {
- CreateEditPoliciesOperation createOperation = (CreateEditPoliciesOperation) operation;
- try {
- if (ServiceUtilsForEditPart.getInstance().getServiceRegistry(createOperation.getEditPart()) != null) {
- return createOperation.getEditPart().getModel() instanceof Node;
- }
- } catch (ServiceException ex) {
- // Do nothing: the services registry is not available.
- }
- }
-
- return false;
- }
-
- @Override
- public void createEditPolicies(EditPart editPart) {
- editPart.installEditPolicy(ExternalReferenceEditPolicy.EDIT_POLICY_ROLE, new ExternalReferenceEditPolicy());
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.CreateEditPoliciesOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpolicy.IEditPolicyProvider;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.gmfdiag.common.editpolicies.ExternalReferenceEditPolicy;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.ServiceUtilsForEditPart;
+
+/**
+ * The EditPolicyProvider for {@link ExternalReferenceEditPolicy} It provides an {@link ExternalReferenceEditPolicy} for Papyrus edit parts, when the
+ * ServicesRegistry is available
+ * This edit policy in only installed on Shapes (Graphical Edges are typically owned by the Diagram, which makes it difficult
+ * to determine whether they are imported or not)
+ *
+ * @author Camille Letavernier
+ */
+public class ExternalReferenceEditPolicyProvider extends AbstractProvider implements IEditPolicyProvider {
+
+ @Override
+ public boolean provides(IOperation operation) {
+ if (operation instanceof CreateEditPoliciesOperation) {
+ CreateEditPoliciesOperation createOperation = (CreateEditPoliciesOperation) operation;
+ try {
+ if (ServiceUtilsForEditPart.getInstance().getServiceRegistry(createOperation.getEditPart()) != null) {
+ return createOperation.getEditPart().getModel() instanceof Node;
+ }
+ } catch (ServiceException ex) {
+ // Do nothing: the services registry is not available.
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public void createEditPolicies(EditPart editPart) {
+ editPart.installEditPolicy(ExternalReferenceEditPolicy.EDIT_POLICY_ROLE, new ExternalReferenceEditPolicy());
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/IThemeInitializer.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/IThemeInitializer.java
index b5f2d409e4c..6614ea2f560 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/IThemeInitializer.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/IThemeInitializer.java
@@ -1,20 +1,20 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.gmf.runtime.notation.View;
-
-
-public interface IThemeInitializer {
-
- public boolean usePreferenceInitializer(View view);
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.gmf.runtime.notation.View;
+
+
+public interface IThemeInitializer {
+
+ public boolean usePreferenceInitializer(View view);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/LineStyleLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/LineStyleLabelProvider.java
index 474046f8ae1..2e7360f9a88 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/LineStyleLabelProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/LineStyleLabelProvider.java
@@ -1,126 +1,126 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.swt.graphics.Image;
-
-/**
- *
- * Label Provider for line style
- *
- */
-public class LineStyleLabelProvider implements ILabelProvider {
-
-
- public static final String LINE_STYLE_SOLID_STRING = "Solid";
-
- public static final String LINE_STYLE_DASH_STRING = "Dash";
-
- public static final String LINE_STYLE_DOT_STRING = "Dot";
-
- public static final String LINE_STYLE_DASH_DOT_STRING = "Dash Dot";
-
- public static final String LINE_STYLE_DASH_DOT_DOT_STRING = "Dash Dot Dot";
-
- public static final String LINE_STYLE_CUSTOM = "Custom";
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
- *
- * @param listener
- */
- @Override
- public void addListener(ILabelProviderListener listener) {
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
- *
- */
- @Override
- public void dispose() {
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
- *
- * @param element
- * @param property
- * @return
- */
- @Override
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
- *
- * @param listener
- */
- @Override
- public void removeListener(ILabelProviderListener listener) {
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Image getImage(Object element) {
- return null;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if (element instanceof Integer) {
- int lineStyle = (Integer) element;
- switch (lineStyle) {
- case Graphics.LINE_SOLID:
- return LINE_STYLE_SOLID_STRING;
- case Graphics.LINE_DASH:
- return LINE_STYLE_DASH_STRING;
- case Graphics.LINE_DOT:
- return LINE_STYLE_DOT_STRING;
- case Graphics.LINE_DASHDOT:
- return LINE_STYLE_DASH_DOT_STRING;
- case Graphics.LINE_DASHDOTDOT:
- return LINE_STYLE_DASH_DOT_DOT_STRING;
- case Graphics.LINE_CUSTOM:
- return LINE_STYLE_CUSTOM;
- default:
- break;
- }
- }
- return null;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ *
+ * Label Provider for line style
+ *
+ */
+public class LineStyleLabelProvider implements ILabelProvider {
+
+
+ public static final String LINE_STYLE_SOLID_STRING = "Solid";
+
+ public static final String LINE_STYLE_DASH_STRING = "Dash";
+
+ public static final String LINE_STYLE_DOT_STRING = "Dot";
+
+ public static final String LINE_STYLE_DASH_DOT_STRING = "Dash Dot";
+
+ public static final String LINE_STYLE_DASH_DOT_DOT_STRING = "Dash Dot Dot";
+
+ public static final String LINE_STYLE_CUSTOM = "Custom";
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
+ *
+ * @param listener
+ */
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
+ *
+ * @param element
+ * @param property
+ * @return
+ */
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
+ *
+ * @param listener
+ */
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Image getImage(Object element) {
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public String getText(Object element) {
+ if (element instanceof Integer) {
+ int lineStyle = (Integer) element;
+ switch (lineStyle) {
+ case Graphics.LINE_SOLID:
+ return LINE_STYLE_SOLID_STRING;
+ case Graphics.LINE_DASH:
+ return LINE_STYLE_DASH_STRING;
+ case Graphics.LINE_DOT:
+ return LINE_STYLE_DOT_STRING;
+ case Graphics.LINE_DASHDOT:
+ return LINE_STYLE_DASH_DOT_STRING;
+ case Graphics.LINE_DASHDOTDOT:
+ return LINE_STYLE_DASH_DOT_DOT_STRING;
+ case Graphics.LINE_CUSTOM:
+ return LINE_STYLE_CUSTOM;
+ default:
+ break;
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationFilteredLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationFilteredLabelProvider.java
index 579d04aec64..22b070ab26d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationFilteredLabelProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/NotationFilteredLabelProvider.java
@@ -1,57 +1,57 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import java.util.Iterator;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
-
-/**
- * A FilteredLabelProvider for GMF Notation model
- *
- * @author Camille Letavernier
- */
-public class NotationFilteredLabelProvider extends NotationLabelProvider implements IFilteredLabelProvider {
-
-
- public boolean accept(IStructuredSelection selection) {
- if (selection.isEmpty()) {
- return false;
- }
-
- Iterator<?> iterator = selection.iterator();
- while (iterator.hasNext()) {
- Object element = iterator.next();
- if (!accept(element)) {
- return false;
- }
- }
-
- return true;
- }
-
- @Override
- public boolean accept(Object element) {
- if (element instanceof IStructuredSelection) {
- return accept((IStructuredSelection) element);
- }
-
- // Accept elements from the Notation metamodel
- EObject eObject = EMFHelper.getEObject(element);
- return eObject != null && eObject.eClass().getEPackage() == NotationPackage.eINSTANCE;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import java.util.Iterator;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.services.labelprovider.service.IFilteredLabelProvider;
+
+/**
+ * A FilteredLabelProvider for GMF Notation model
+ *
+ * @author Camille Letavernier
+ */
+public class NotationFilteredLabelProvider extends NotationLabelProvider implements IFilteredLabelProvider {
+
+
+ public boolean accept(IStructuredSelection selection) {
+ if (selection.isEmpty()) {
+ return false;
+ }
+
+ Iterator<?> iterator = selection.iterator();
+ while (iterator.hasNext()) {
+ Object element = iterator.next();
+ if (!accept(element)) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ @Override
+ public boolean accept(Object element) {
+ if (element instanceof IStructuredSelection) {
+ return accept((IStructuredSelection) element);
+ }
+
+ // Accept elements from the Notation metamodel
+ EObject eObject = EMFHelper.getEObject(element);
+ return eObject != null && eObject.eClass().getEPackage() == NotationPackage.eINSTANCE;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/RestrictedAbstractEditPartProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/RestrictedAbstractEditPartProvider.java
index 03643c6bd2d..a04559bd35d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/RestrictedAbstractEditPartProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/RestrictedAbstractEditPartProvider.java
@@ -1,61 +1,61 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
-
-/**
- * This abstract edit part provider restricts its contribution to view that are owned by
- * a given type of diagram.
- */
-public abstract class RestrictedAbstractEditPartProvider extends AbstractEditPartProvider {
-
- /** The provides only provides for this diagram type */
- protected String diagramType;
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean provides(IOperation operation) {
- if (operation instanceof CreateGraphicEditPartOperation) {
- String currentDiagramType = ((IEditPartOperation) operation).getView().getDiagram().getType();
-
- if ((diagramType == null) || (!diagramType.equals(currentDiagramType))) {
- return false;
- }
- }
-
- return super.provides(operation);
- }
-
-
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ /*****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpart.AbstractEditPartProvider;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpart.CreateGraphicEditPartOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.editpart.IEditPartOperation;
+
+/**
+ * This abstract edit part provider restricts its contribution to view that are owned by
+ * a given type of diagram.
+ */
+public abstract class RestrictedAbstractEditPartProvider extends AbstractEditPartProvider {
+
+ /** The provides only provides for this diagram type */
+ protected String diagramType;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean provides(IOperation operation) {
+ if (operation instanceof CreateGraphicEditPartOperation) {
+ String currentDiagramType = ((IEditPartOperation) operation).getView().getDiagram().getType();
+
+ if ((diagramType == null) || (!diagramType.equals(currentDiagramType))) {
+ return false;
+ }
+ }
+
+ return super.provides(operation);
+ }
+
+
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecoratorProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecoratorProvider.java
index a36cd20a1c6..f30c5dc7fba 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecoratorProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ShapeDecoratorProvider.java
@@ -1,76 +1,76 @@
-/*****************************************************************************
- * Copyright (c) 2009-2010 CEA LIST.
- *
- *
- * 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:
- * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
-import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
-import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
-
-/**
- * Provides the decorator for the shape, based on the shape service
- */
-public class ShapeDecoratorProvider extends AbstractProvider implements IDecoratorProvider {
-
- /** The key used for the mood decoration */
- public static final String SHAPE_DECORATOR = "ShapeDecorator"; //$NON-NLS-1$
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void createDecorators(IDecoratorTarget decoratorTarget) {
- View node = ShapeDecorator.getDecoratorTargetNode(decoratorTarget);
- if (node != null) {
- decoratorTarget.installDecorator(SHAPE_DECORATOR, new ShapeDecorator(decoratorTarget));
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean provides(IOperation operation) {
- Assert.isNotNull(operation);
-
- if (!(operation instanceof CreateDecoratorsOperation)) {
- return false;
- }
-
- IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation).getDecoratorTarget();
-
- View notationElement = NotationHelper.findView(decoratorTarget);
- if (notationElement == null) {
- return false;
- }
-
- try {
- ServicesRegistry papyrusRegistry = ServiceUtilsForEObject.getInstance().getServiceRegistry(notationElement);
- if (papyrusRegistry == null) {
- return false;
- }
- } catch (Exception ex) {
- return false; // Not a Papyrus model
- }
-
- return ShapeDecorator.getDecoratorTargetNode(decoratorTarget) != null;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2009-2010 CEA LIST.
+ *
+ *
+ * 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:
+ * Vincent Lorenzo (CEA LIST) vincent.lorenzo@cea.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.CreateDecoratorsOperation;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorProvider;
+import org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoratorTarget;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.helper.NotationHelper;
+
+/**
+ * Provides the decorator for the shape, based on the shape service
+ */
+public class ShapeDecoratorProvider extends AbstractProvider implements IDecoratorProvider {
+
+ /** The key used for the mood decoration */
+ public static final String SHAPE_DECORATOR = "ShapeDecorator"; //$NON-NLS-1$
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createDecorators(IDecoratorTarget decoratorTarget) {
+ View node = ShapeDecorator.getDecoratorTargetNode(decoratorTarget);
+ if (node != null) {
+ decoratorTarget.installDecorator(SHAPE_DECORATOR, new ShapeDecorator(decoratorTarget));
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean provides(IOperation operation) {
+ Assert.isNotNull(operation);
+
+ if (!(operation instanceof CreateDecoratorsOperation)) {
+ return false;
+ }
+
+ IDecoratorTarget decoratorTarget = ((CreateDecoratorsOperation) operation).getDecoratorTarget();
+
+ View notationElement = NotationHelper.findView(decoratorTarget);
+ if (notationElement == null) {
+ return false;
+ }
+
+ try {
+ ServicesRegistry papyrusRegistry = ServiceUtilsForEObject.getInstance().getServiceRegistry(notationElement);
+ if (papyrusRegistry == null) {
+ return false;
+ }
+ } catch (Exception ex) {
+ return false; // Not a Papyrus model
+ }
+
+ return ShapeDecorator.getDecoratorTargetNode(decoratorTarget) != null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ThemeInitializerManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ThemeInitializerManager.java
index 5902e1a6789..bac77861514 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ThemeInitializerManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/ThemeInitializerManager.java
@@ -1,51 +1,51 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-
-public class ThemeInitializerManager {
-
- private static final String EXTENSION_ID = Activator.ID + ".initializeView";
-
- public static final IThemeInitializer instance = loadThemeInitializer();
-
- private static IThemeInitializer loadThemeInitializer() {
- IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
-
- for (IConfigurationElement e : config) {
- try {
- final IThemeInitializer initializer = (IThemeInitializer) e.createExecutableExtension("initializeView"); //$NON-NLS-1$
- if (initializer != null) {
- return initializer;
- }
- } catch (Exception ex) {
- Activator.log.error("The plugin " + e.getContributor().getName() + " contributed an invalid extension for " + EXTENSION_ID, ex);
- }
- }
-
- return new DefaultThemeInitializer();
- }
-
- private static class DefaultThemeInitializer implements IThemeInitializer {
-
- @Override
- public boolean usePreferenceInitializer(View view) {
- return true;
- }
-
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+
+public class ThemeInitializerManager {
+
+ private static final String EXTENSION_ID = Activator.ID + ".initializeView";
+
+ public static final IThemeInitializer instance = loadThemeInitializer();
+
+ private static IThemeInitializer loadThemeInitializer() {
+ IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+
+ for (IConfigurationElement e : config) {
+ try {
+ final IThemeInitializer initializer = (IThemeInitializer) e.createExecutableExtension("initializeView"); //$NON-NLS-1$
+ if (initializer != null) {
+ return initializer;
+ }
+ } catch (Exception ex) {
+ Activator.log.error("The plugin " + e.getContributor().getName() + " contributed an invalid extension for " + EXTENSION_ID, ex);
+ }
+ }
+
+ return new DefaultThemeInitializer();
+ }
+
+ private static class DefaultThemeInitializer implements IThemeInitializer {
+
+ @Override
+ public boolean usePreferenceInitializer(View view) {
+ return true;
+ }
+
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/UnitsLabelProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/UnitsLabelProvider.java
index ed279286ea7..238ac1214ea 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/UnitsLabelProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/providers/UnitsLabelProvider.java
@@ -1,112 +1,112 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.providers;
-
-import org.eclipse.gef.rulers.RulerProvider;
-import org.eclipse.jface.viewers.ILabelProvider;
-import org.eclipse.jface.viewers.ILabelProviderListener;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.UnitsConstants;
-import org.eclipse.swt.graphics.Image;
-
-/**
- *
- * Label provider for Units
- *
- */
-public class UnitsLabelProvider implements ILabelProvider {
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
- *
- * @param listener
- */
- @Override
- public void addListener(ILabelProviderListener listener) {
- // not used
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
- *
- */
- @Override
- public void dispose() {
- // not used
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
- *
- * @param element
- * @param property
- * @return
- */
- @Override
- public boolean isLabelProperty(Object element, String property) {
- return false;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
- *
- * @param listener
- */
- @Override
- public void removeListener(ILabelProviderListener listener) {
- // not used
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public Image getImage(Object element) {
- // not used
- return null;
- }
-
- /**
- *
- * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
- *
- * @param element
- * @return
- */
- @Override
- public String getText(Object element) {
- if (element instanceof Integer) {
- final int unit = (Integer) element;
- switch (unit) {
- case RulerProvider.UNIT_INCHES:
- return UnitsConstants.INCHES;
- case RulerProvider.UNIT_CENTIMETERS:
- return UnitsConstants.CENTIMETERS;
- case RulerProvider.UNIT_PIXELS:
- return UnitsConstants.PIXELS;
- default:
- break;
- }
- }
- return "";
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.providers;
+
+import org.eclipse.gef.rulers.RulerProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.ILabelProviderListener;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.UnitsConstants;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ *
+ * Label provider for Units
+ *
+ */
+public class UnitsLabelProvider implements ILabelProvider {
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
+ *
+ * @param listener
+ */
+ @Override
+ public void addListener(ILabelProviderListener listener) {
+ // not used
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
+ *
+ */
+ @Override
+ public void dispose() {
+ // not used
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
+ *
+ * @param element
+ * @param property
+ * @return
+ */
+ @Override
+ public boolean isLabelProperty(Object element, String property) {
+ return false;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
+ *
+ * @param listener
+ */
+ @Override
+ public void removeListener(ILabelProviderListener listener) {
+ // not used
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public Image getImage(Object element) {
+ // not used
+ return null;
+ }
+
+ /**
+ *
+ * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
+ *
+ * @param element
+ * @return
+ */
+ @Override
+ public String getText(Object element) {
+ if (element instanceof Integer) {
+ final int unit = (Integer) element;
+ switch (unit) {
+ case RulerProvider.UNIT_INCHES:
+ return UnitsConstants.INCHES;
+ case RulerProvider.UNIT_CENTIMETERS:
+ return UnitsConstants.CENTIMETERS;
+ case RulerProvider.UNIT_PIXELS:
+ return UnitsConstants.PIXELS;
+ default:
+ break;
+ }
+ }
+ return "";
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/reconciler/DiagramReconcilersReader.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/reconciler/DiagramReconcilersReader.java
index f44816300ea..72c067aff0c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/reconciler/DiagramReconcilersReader.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/reconciler/DiagramReconcilersReader.java
@@ -1,175 +1,175 @@
-package org.eclipse.papyrus.infra.gmfdiag.common.reconciler;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.emf.ecore.plugin.RegistryReader;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-public class DiagramReconcilersReader extends RegistryReader {
-
- private static volatile DiagramReconcilersReader ourInstance = null;
-
- private static final String EXT_PT = "diagramReconciler"; //$NON-NLS-1$
-
- private static final String TAG_DIAGRAM_RECONCILER = "diagramReconciler"; //$NON-NLS-1$
-
- private Map<String, Collection<DiagramReconciler>> myReconcilers;
-
- /**
- * Read-only view on the myReconcilers bag. Only available when myReconcilers != null
- */
- private Map<String, Collection<DiagramReconciler>> myReconcilersRO;
-
- public final static DiagramReconcilersReader getInstance() {
- if (ourInstance == null) {
- synchronized (DiagramReconcilersReader.class) {
- if (ourInstance == null) {
- ourInstance = new DiagramReconcilersReader();
- }
- }
- }
- return ourInstance;
- }
-
- DiagramReconcilersReader() {
- super(Platform.getExtensionRegistry(), Activator.ID, EXT_PT);
- }
-
- /**
- * @return unmodifiable map of loaded reconcilers
- */
- public synchronized Map<String, Collection<DiagramReconciler>> load() {
- if (myReconcilers == null) {
- myReconcilers = new HashMap<String, Collection<DiagramReconciler>>();
- myReconcilersRO = Collections.unmodifiableMap(myReconcilers);
- readRegistry();
- }
- return myReconcilersRO;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.emf.ecore.plugin.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement, boolean)
- */
- @Override
- protected boolean readElement(IConfigurationElement element, boolean add) {
- if (!TAG_DIAGRAM_RECONCILER.equals(element.getName())) {
- return false;
- }
-
- String className = element.getAttribute(DiagramReconciler.ATTR_RECONCILER_CLASS);
- String diagramTypeString = element.getAttribute(DiagramReconciler.ATTR_DIAGRAM_TYPE);
- String sourceVersion = element.getAttribute(DiagramReconciler.ATTR_SOURCE_VERSION);
- String targetVersion = element.getAttribute(DiagramReconciler.ATTR_TARGET_VERSION);
-
- if (!checkNotEmpty(className)) {
- logMissingAttribute(element, DiagramReconciler.ATTR_RECONCILER_CLASS);
- return false;
- }
- if (!checkNotEmpty(diagramTypeString)) {
- logMissingAttribute(element, DiagramReconciler.ATTR_DIAGRAM_TYPE);
- return false;
- }
- if (!checkNotEmpty(sourceVersion)) {
- logMissingAttribute(element, DiagramReconciler.ATTR_SOURCE_VERSION);
- return false;
- }
-
- if (!checkNotEmpty(targetVersion)) {
- logMissingAttribute(element, DiagramReconciler.ATTR_TARGET_VERSION);
- return false;
- }
- if (!DiagramVersioningUtils.isCurrentPapyrusVersion(targetVersion)) {
- Activator.log.debug("Reconciler for outdated version is still registered but will never be executed: " + className); //$NON-NLS-1$
- return false;
- }
-
-
- if (add) {
- addDiagramReconciler(element);
- } else {
- removeDiagramReconciler(element);
- }
-
- return true;
- }
-
- private static boolean checkNotEmpty(String attr) {
- return (attr != null) && (attr.length() != 0);
- }
-
- protected void addDiagramReconciler(IConfigurationElement element) {
- DiagramReconciler reconciler = createReconciler(element);
- if (reconciler != null) {
- synchronized (myReconcilers) {
- String diagramType = reconciler.getDiagramVisualID();
- Collection<DiagramReconciler> listForType = myReconcilers.get(diagramType);
- if (listForType == null) {
- listForType = new LinkedList<DiagramReconciler>();
- myReconcilers.put(diagramType, listForType);
- }
- listForType.add(reconciler);
- }
- }
- }
-
- /**
- * Unregisters reconciler defined by given extension element.
- * <p/>
- * Only diagram type and fully qualified class name will be used to find the one instance to remove.
- */
- protected void removeDiagramReconciler(IConfigurationElement element) {
- String diagramTypeString = element.getAttribute(DiagramReconciler.ATTR_DIAGRAM_TYPE);
- String fqn = element.getAttribute(DiagramReconciler.ATTR_RECONCILER_CLASS);
- if (diagramTypeString == null || fqn == null) {
- // we already have skipped this config at the time of addition
- return;
- }
-
- synchronized (myReconcilers) {
- Collection<DiagramReconciler> reconcilers = myReconcilers.get(diagramTypeString);
- if (reconcilers != null) {
- for (Iterator<DiagramReconciler> it = reconcilers.iterator(); it.hasNext();) {
- DiagramReconciler next = it.next();
- if (fqn.equals(next.getClassFqn())) {
- it.remove();
- break;
- }
- }
- if (reconcilers.size() == 0) {
- myReconcilers.remove(diagramTypeString);
- }
- }
- }
- }
-
- /**
- * Instantiates the reconciler defined by given extension
- *
- * @param element
- * @return configured reconciler instance or <code>null</code> if something bad happens (error is logged in this case)
- */
- private DiagramReconciler createReconciler(IConfigurationElement element) {
- try {
- Object diagramReconcilerObject = element.createExecutableExtension(DiagramReconciler.ATTR_RECONCILER_CLASS);
- if (diagramReconcilerObject instanceof DiagramReconciler) {
- return (DiagramReconciler) diagramReconcilerObject;
- } else {
- Activator.log.error("Diagram reconciler extension does not extend mandatory DiagramReconciler base class: " + element.getAttribute(DiagramReconciler.ATTR_RECONCILER_CLASS), null); //$NON-NLS-1$
- }
- } catch (CoreException e) {
- Activator.getInstance().getLog().log(e.getStatus());
- }
- return null;
- }
-
-}
+package org.eclipse.papyrus.infra.gmfdiag.common.reconciler;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.emf.ecore.plugin.RegistryReader;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+public class DiagramReconcilersReader extends RegistryReader {
+
+ private static volatile DiagramReconcilersReader ourInstance = null;
+
+ private static final String EXT_PT = "diagramReconciler"; //$NON-NLS-1$
+
+ private static final String TAG_DIAGRAM_RECONCILER = "diagramReconciler"; //$NON-NLS-1$
+
+ private Map<String, Collection<DiagramReconciler>> myReconcilers;
+
+ /**
+ * Read-only view on the myReconcilers bag. Only available when myReconcilers != null
+ */
+ private Map<String, Collection<DiagramReconciler>> myReconcilersRO;
+
+ public final static DiagramReconcilersReader getInstance() {
+ if (ourInstance == null) {
+ synchronized (DiagramReconcilersReader.class) {
+ if (ourInstance == null) {
+ ourInstance = new DiagramReconcilersReader();
+ }
+ }
+ }
+ return ourInstance;
+ }
+
+ DiagramReconcilersReader() {
+ super(Platform.getExtensionRegistry(), Activator.ID, EXT_PT);
+ }
+
+ /**
+ * @return unmodifiable map of loaded reconcilers
+ */
+ public synchronized Map<String, Collection<DiagramReconciler>> load() {
+ if (myReconcilers == null) {
+ myReconcilers = new HashMap<String, Collection<DiagramReconciler>>();
+ myReconcilersRO = Collections.unmodifiableMap(myReconcilers);
+ readRegistry();
+ }
+ return myReconcilersRO;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.emf.ecore.plugin.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement, boolean)
+ */
+ @Override
+ protected boolean readElement(IConfigurationElement element, boolean add) {
+ if (!TAG_DIAGRAM_RECONCILER.equals(element.getName())) {
+ return false;
+ }
+
+ String className = element.getAttribute(DiagramReconciler.ATTR_RECONCILER_CLASS);
+ String diagramTypeString = element.getAttribute(DiagramReconciler.ATTR_DIAGRAM_TYPE);
+ String sourceVersion = element.getAttribute(DiagramReconciler.ATTR_SOURCE_VERSION);
+ String targetVersion = element.getAttribute(DiagramReconciler.ATTR_TARGET_VERSION);
+
+ if (!checkNotEmpty(className)) {
+ logMissingAttribute(element, DiagramReconciler.ATTR_RECONCILER_CLASS);
+ return false;
+ }
+ if (!checkNotEmpty(diagramTypeString)) {
+ logMissingAttribute(element, DiagramReconciler.ATTR_DIAGRAM_TYPE);
+ return false;
+ }
+ if (!checkNotEmpty(sourceVersion)) {
+ logMissingAttribute(element, DiagramReconciler.ATTR_SOURCE_VERSION);
+ return false;
+ }
+
+ if (!checkNotEmpty(targetVersion)) {
+ logMissingAttribute(element, DiagramReconciler.ATTR_TARGET_VERSION);
+ return false;
+ }
+ if (!DiagramVersioningUtils.isCurrentPapyrusVersion(targetVersion)) {
+ Activator.log.debug("Reconciler for outdated version is still registered but will never be executed: " + className); //$NON-NLS-1$
+ return false;
+ }
+
+
+ if (add) {
+ addDiagramReconciler(element);
+ } else {
+ removeDiagramReconciler(element);
+ }
+
+ return true;
+ }
+
+ private static boolean checkNotEmpty(String attr) {
+ return (attr != null) && (attr.length() != 0);
+ }
+
+ protected void addDiagramReconciler(IConfigurationElement element) {
+ DiagramReconciler reconciler = createReconciler(element);
+ if (reconciler != null) {
+ synchronized (myReconcilers) {
+ String diagramType = reconciler.getDiagramVisualID();
+ Collection<DiagramReconciler> listForType = myReconcilers.get(diagramType);
+ if (listForType == null) {
+ listForType = new LinkedList<DiagramReconciler>();
+ myReconcilers.put(diagramType, listForType);
+ }
+ listForType.add(reconciler);
+ }
+ }
+ }
+
+ /**
+ * Unregisters reconciler defined by given extension element.
+ * <p/>
+ * Only diagram type and fully qualified class name will be used to find the one instance to remove.
+ */
+ protected void removeDiagramReconciler(IConfigurationElement element) {
+ String diagramTypeString = element.getAttribute(DiagramReconciler.ATTR_DIAGRAM_TYPE);
+ String fqn = element.getAttribute(DiagramReconciler.ATTR_RECONCILER_CLASS);
+ if (diagramTypeString == null || fqn == null) {
+ // we already have skipped this config at the time of addition
+ return;
+ }
+
+ synchronized (myReconcilers) {
+ Collection<DiagramReconciler> reconcilers = myReconcilers.get(diagramTypeString);
+ if (reconcilers != null) {
+ for (Iterator<DiagramReconciler> it = reconcilers.iterator(); it.hasNext();) {
+ DiagramReconciler next = it.next();
+ if (fqn.equals(next.getClassFqn())) {
+ it.remove();
+ break;
+ }
+ }
+ if (reconcilers.size() == 0) {
+ myReconcilers.remove(diagramTypeString);
+ }
+ }
+ }
+ }
+
+ /**
+ * Instantiates the reconciler defined by given extension
+ *
+ * @param element
+ * @return configured reconciler instance or <code>null</code> if something bad happens (error is logged in this case)
+ */
+ private DiagramReconciler createReconciler(IConfigurationElement element) {
+ try {
+ Object diagramReconcilerObject = element.createExecutableExtension(DiagramReconciler.ATTR_RECONCILER_CLASS);
+ if (diagramReconcilerObject instanceof DiagramReconciler) {
+ return (DiagramReconciler) diagramReconcilerObject;
+ } else {
+ Activator.log.error("Diagram reconciler extension does not extend mandatory DiagramReconciler base class: " + element.getAttribute(DiagramReconciler.ATTR_RECONCILER_CLASS), null); //$NON-NLS-1$
+ }
+ } catch (CoreException e) {
+ Activator.getInstance().getLog().log(e.getStatus());
+ }
+ return null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandDragTracker.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandDragTracker.java
index 25614b399fa..646f61df06a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandDragTracker.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandDragTracker.java
@@ -1,47 +1,47 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.selection;
-
-import org.eclipse.gef.DragTracker;
-
-
-/**
- * This DragTracker extends the PapyrusRubberbandSelectionTool.
- * This class is called by the method getDragTracker() in the PapyrusDiagramEditPart.
- *
- * @author cjanssens
- */
-public class PapyrusRubberbandDragTracker extends PapyrusRubberbandSelectionTool implements DragTracker {
-
-
- /**
- * Constructor.
- */
- public PapyrusRubberbandDragTracker() {
- super();
- setMarqueeBehavior(BEHAVIOR_OBJECT_INCLUDED);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleFinished()
- */
- @Override
- protected void handleFinished() {
- // nothing goes here
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.selection;
+
+import org.eclipse.gef.DragTracker;
+
+
+/**
+ * This DragTracker extends the PapyrusRubberbandSelectionTool.
+ * This class is called by the method getDragTracker() in the PapyrusDiagramEditPart.
+ *
+ * @author cjanssens
+ */
+public class PapyrusRubberbandDragTracker extends PapyrusRubberbandSelectionTool implements DragTracker {
+
+
+ /**
+ * Constructor.
+ */
+ public PapyrusRubberbandDragTracker() {
+ super();
+ setMarqueeBehavior(BEHAVIOR_OBJECT_INCLUDED);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleFinished()
+ */
+ @Override
+ protected void handleFinished() {
+ // nothing goes here
+
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandSelectionTool.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandSelectionTool.java
index e385e8ff6d9..563793f59ea 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandSelectionTool.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/PapyrusRubberbandSelectionTool.java
@@ -1,850 +1,850 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- *
- * Céline Janssens - inspired by IBM class RubberbandSelectionTool : modify the calculateNewSelection method and add constructors
- *
- ****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.selection;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Set;
-
-import javax.swing.plaf.basic.BasicComboBoxUI.KeyHandler;
-
-import org.eclipse.draw2d.ColorConstants;
-import org.eclipse.draw2d.Connection;
-import org.eclipse.draw2d.Cursors;
-import org.eclipse.draw2d.Figure;
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.Graphics;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.GraphicalViewer;
-import org.eclipse.gef.LayerConstants;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.editparts.LayerManager;
-import org.eclipse.gef.tools.AbstractTool;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.util.SelectInDiagramHelper;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * A Tool which selects multiple objects inside a rectangular area of a Graphical Viewer.<br/>
- * If the SHIFT key is pressed at the beginning of the drag, the enclosed items will be
- * appended to the current selection.<br/>
- * If the CONTROL key is pressed at the beginning of
- * the drag, the enclosed items will have their selection state inverted.
- * <P>
- * This tool is inspired from RubberbandSelectionTool to add some features.
- * <li>Labels , affixed child nodes and connections are part of the eligible Edit Parts to be selected</li>
- * <li>Additional constructors allow to select which behavior and which kind of editParts will be part of the selection</li>
- * <li>Additional members allow to select which behavior and which kind of editParts are part of the selection</li>
- * <li>Even the not visible EditParts inside of a container (due to scroll bars) will be part of selection</li>
- */
-public class PapyrusRubberbandSelectionTool extends AbstractTool {
-
- /**
- * Mode in case of CTRL modifier key.
- */
- static final int TOGGLE_MODE = 1;
-
- /**
- * Mode in case of SHIFT modifier key.
- */
- static final int APPEND_MODE = 2;
-
- private int mode;
-
- private Figure marqueeRectangleFigure;
-
- private Set<EditPart> allChildren = new HashSet<EditPart>();
-
- private List<EditPart> selectedEditParts;
-
- private Request targetRequest;
-
- private Point feedBackStartLocation = null;
-
- private WeakReference<?> weakReference;
-
- private static final Request MARQUEE_REQUEST = new Request(RequestConstants.REQ_SELECTION);
-
- /**
- * Standard Marquee Selection behavior.
- */
- public static final int BEHAVIOR_OBJECT_INCLUDED = new Integer(1).intValue();
-
- /**
- * Rubberband Marquee Selection behavior.
- */
- public static final int BEHAVIOR_OBJECT_TOUCHED = new Integer(2).intValue();
-
- /**
- * Default Marquee Selection behavior.
- */
- public static final int DEFAULT_MARQUEE_BEHAVIOR = BEHAVIOR_OBJECT_INCLUDED;
-
-
- private int marqueeBehavior = DEFAULT_MARQUEE_BEHAVIOR;
-
- /**
- * Define if the nodes should be part of the selection by default
- */
- public static final boolean DEFAULT_SELECT_NODES = true;
-
- /**
- * Define if the Labels should be part of the selection by default
- */
- public static final boolean DEFAULT_SELECT_LABELS = true;
-
- /**
- * Define if the Connections should be part of the selection by default
- */
- public static final boolean DEFAULT_SELECT_CONNECTIONS = true;
-
- /**
- * Parameter to define if Nodes should be part of the selection
- */
- private boolean selectNodes = DEFAULT_SELECT_NODES;
-
- /**
- * Parameter to define if Labels should be part of the selection
- */
- private boolean selectLabels = DEFAULT_SELECT_LABELS;
-
- /**
- * Parameter to define if Connections should be part of the selection
- */
- private boolean selectConnections = DEFAULT_SELECT_CONNECTIONS;
-
-
- /**
- * Constructor.
- * Creates a new MarqueeSelectionTool.
- */
- public PapyrusRubberbandSelectionTool() {
- setDefaultCursor(Cursors.CROSS);
- setUnloadWhenFinished(false);
- }
-
-
- /**
- * Constructor.
- *
- * @param behavior
- * <li>BEHAVIOR_OBJECT_INCLUDE = 1</li> <li>BEHAVIOR_OBJECT_TOUCHED = 2</li>
- */
- public PapyrusRubberbandSelectionTool(int behavior) {
- this();
- this.setMarqueeBehavior(behavior);
- }
-
-
- /**
- * Constructor.
- *
- * @param behavior
- * Define what behavior is expected by the tool.
- *
- * <li>BEHAVIOR_OBJECT_INCLUDE = 1</li> <li>BEHAVIOR_OBJECT_TOUCHED = 2</li>
- * @param nodeSelectable
- * true if Nodes should be selected
- * @param labelSelectable
- * true if Labels should be selected
- * @param connectionSelectable
- * true if Connections should be selected
- */
- public PapyrusRubberbandSelectionTool(int behavior, boolean nodeSelectable, boolean labelSelectable, boolean connectionSelectable) {
- this(behavior);
-
- this.setSelectNodes(nodeSelectable);
- this.setSelectLabels(labelSelectable);
- this.setSelectConnections(connectionSelectable);
-
- }
-
- /**
- * Defines if Nodes must be part of the selection
- *
- * @return selectNodes
- */
- public boolean isSelectNodes() {
- return selectNodes;
- }
-
- /**
- * Set if the Nodes should be part of the selection.
- *
- * @param selectNodes
- */
- public void setSelectNodes(boolean selectNodes) {
- this.selectNodes = selectNodes;
- }
-
- /**
- * Defines if Labels must be part of the selection
- *
- * @return selectLabels
- */
- public boolean isSelectLabels() {
- return selectLabels;
- }
-
- /**
- * Set if the Labels should be part of the selection.
- *
- * @param selectLabels
- */
- public void setSelectLabels(boolean selectLabels) {
- this.selectLabels = selectLabels;
- }
-
-
-
- /**
- * Defines if Connection must be part of the selection
- *
- * @return selectNodes
- */
- public boolean isSelectConnections() {
- return selectConnections;
- }
-
- /**
- * Set if the Connections should be part of the selection.
- *
- * @param selectConnections
- */
- public void setSelectConnections(boolean selectConnections) {
- this.selectConnections = selectConnections;
- }
-
-
- /**
- * Calculate the selection of the Rubberband: <li>List all the eligible Edit parts</li> <li>Keep only if include in the Marquee rectangle</li> <li>
- * Add in the selection if the EditPart type (connection, Label and node) is requested into the selection</li>
- *
- * @return List of EditParts which meet the conditions of the selection
- */
- private List calculateNewSelection() {
-
- List<EditPart> newSelections = new ArrayList<EditPart>();
- Iterator<EditPart> children = getAllChildren().iterator();
-
- // Calculate new selections based on which children fall
- // inside the marquee selection rectangle.
- // Select Nodes, Labels and Connections
- while (children.hasNext()) {
-
- EditPart child = children.next();
-
- if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child) {
- continue;
- }
-
- // if the child is part of the Marquee selection add it to the list of selected EditParts
- if (isPartOfMarqueeSelection(marqueeBehavior, child)) {
-
- // if the child is a node and the nodes must be selected then add the child to the selection
- if (isNode(child) && isSelectNodes()) {
- newSelections.add(child);
- } else if (isLabel(child) && isSelectLabels()) {
- newSelections.add(child);
- } else if (isConnection(child) && isSelectConnections()) {
- newSelections.add(child);
- } else {
- continue;
- }
- }
- }
-
- return newSelections;
- }
-
- /**
- * Check if an edit Part is a Node
- *
- * @return
- */
- private boolean isNode(EditPart editPart) {
-
- return (editPart instanceof ShapeEditPart);
- }
-
-
- /**
- * Check if an edit Part is a Label
- *
- * @return
- */
- private boolean isLabel(EditPart editPart) {
-
- return (editPart instanceof LabelEditPart);
- }
-
-
- /**
- * Check if an edit Part is a Connection
- *
- * @return
- */
- private boolean isConnection(EditPart editPart) {
-
- return (editPart instanceof ConnectionEditPart);
- }
-
- /**
- * Calculate if the editPart should be part of the selection depending on the wished marquee behavior.
- *
- * @param marqueeBehavior
- * wished behavior for the selection (BEHAVIOR_OBJECT_INCLUDED, BEHAVIOR_OBJECT_TOUCHED, ...)
- * @param editPart
- * EditPart for which the selection is calculated
- *
- * @return <b>true</b> if the editPart is part of the selection.
- */
- private boolean isPartOfMarqueeSelection(int marqueeBehaviorType, EditPart editPart) {
-
-
- boolean isInside = false;
- boolean isTouched = false;
- boolean isPartOfSelection = false;
-
- IFigure figure = ((GraphicalEditPart) editPart).getFigure();
- Rectangle marqueeBounds = getMarqueeBounds();
-
- Rectangle figureRectangle;
- if (editPart instanceof ConnectionEditPart) {
- // RATLC00569348 For connection, get the bounds of connection points rather than connection figure since the
- // figure's bounds contain the bounds of all connection editParts and would require selection rectangle
- // to be larger than expected in some cases
- figureRectangle = ((Connection) figure).getPoints().getBounds().getCopy();
- } else {
- figureRectangle = figure.getBounds().getCopy();
- }
- figure.translateToAbsolute(figureRectangle);
- getMarqueeFeedbackFigure().translateToRelative(figureRectangle);
-
- // If the objects are included into the Marquee Rectangle
- isInside = (marqueeBounds.contains(figureRectangle.getTopLeft()) && marqueeBounds.contains(figureRectangle.getBottomRight()));
-
- // If the objects are intersected by the Marquee Rectangle
- isTouched = isTouchedByMarquee(marqueeBounds, figureRectangle);
-
- if (marqueeBehaviorType == BEHAVIOR_OBJECT_INCLUDED) {
- // Part of the selection only if inside
- isPartOfSelection = isInside;
-
- } else if (marqueeBehaviorType == BEHAVIOR_OBJECT_TOUCHED) {
- // Part of the selection if inside or touched by the marquee
- isPartOfSelection = isInside || isTouched;
-
- }
- return isPartOfSelection;
-
- }
-
- /**
- * Define if the EditPart intersects the marquee rectangle.
- *
- * @param marqueeBounds
- * The Marquee rectangle
- * @param figureBounds
- * The EditPart Figure Rectangle
- * @return true if the intersection is not null
- */
- private boolean isTouchedByMarquee(Rectangle marqueeBounds, Rectangle figureBounds) {
- // return true if the intersection is not null
- return figureBounds.intersects(marqueeBounds);
-
- }
-
-
- /**
- * Default getter of the Marquee Behavior
- *
- * @return behavior: <li>BEHAVIOR_OBJECT_INCLUDE = 1</li> <li>BEHAVIOR_OBJECT_TOUCHED = 2</li>
- */
- public int getMarqueeBehavior() {
- return marqueeBehavior;
- }
-
- /**
- * Default setter
- *
- * @param marqueeBehavior
- */
- public void setMarqueeBehavior(int marqueeBehavior) {
- this.marqueeBehavior = marqueeBehavior;
- }
-
-
- protected Request createTargetRequest() {
- return MARQUEE_REQUEST;
- }
-
- /**
- * Erases feedback if necessary and puts the tool into the terminal state.
- */
- @Override
- public void deactivate() {
- if (isInState(STATE_DRAG_IN_PROGRESS)) {
- eraseMarqueeFeedback();
- eraseTargetFeedback();
- }
- super.deactivate();
- allChildren = new HashSet<EditPart>();
- setState(STATE_TERMINAL);
- }
-
- private void eraseMarqueeFeedback() {
- if (marqueeRectangleFigure != null) {
- removeFeedback(marqueeRectangleFigure);
- marqueeRectangleFigure = null;
- }
- feedBackStartLocation = null;
- }
-
- protected void eraseTargetFeedback() {
- if (selectedEditParts == null) {
- return;
- }
- ListIterator<EditPart> oldEditParts = selectedEditParts.listIterator();
- while (oldEditParts.hasNext()) {
- EditPart editPart = oldEditParts.next();
- editPart.eraseTargetFeedback(getTargetRequest());
- }
- }
-
-
-
- /**
- * Returns a list including all of the children
- * of the edit part passed in.
- */
- private HashSet<EditPart> getAllChildren(EditPart editPart, HashSet<EditPart> currentSelection) {
-
- // List all the editPart children
- List<EditPart> children = editPart.getChildren();
-
- // for each child, add the child and all its connections to the currentSelection
- for (int i = 0; i < children.size(); i++) {
-
- GraphicalEditPart child = (GraphicalEditPart) children.get(i);
-
- currentSelection.add(child);
-
- getAllChildren(child, currentSelection);
-
- List sourceConnections = child.getSourceConnections();
- List targetConnections = child.getTargetConnections();
-
-
- // Add all the connection and they children into the List of all the Objects to be selected
- // Connection children are all its labels
- for (int j = 0; j < sourceConnections.size(); j++) {
-
- // Add the connection
- currentSelection.add((GraphicalEditPart) sourceConnections.get(j));
- // Add the connection children (Labels)
- getAllChildren((EditPart) sourceConnections.get(j), currentSelection);
- }
-
- // Add all the connection and they children into the List of all the Objects to be selected
- for (int k = 0; k < targetConnections.size(); k++) {
-
- // Add the connection
- currentSelection.add((GraphicalEditPart) targetConnections.get(k));
- // Add the connection children (Labels)
- getAllChildren((EditPart) targetConnections.get(k), currentSelection);
-
- }
-
- }
-
-
- return currentSelection;
- }
-
- /**
- * Return a vector including all of the children
- * of the root editpart
- */
- private Set<EditPart> getAllChildren() {
- if (allChildren.isEmpty()) {
- allChildren = getAllChildren(getCurrentViewer().getContents(), new HashSet<EditPart>());
- }
- return allChildren;
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
- */
- @Override
- protected String getCommandName() {
- return REQ_SELECTION;
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
- */
- @Override
- protected String getDebugName() {
- return "Marquee Tool";//$NON-NLS-1$
- }
-
- protected IFigure getMarqueeFeedbackFigure() {
- if (marqueeRectangleFigure == null) {
- marqueeRectangleFigure = new MarqueeRectangleFigure();
- addFeedback(marqueeRectangleFigure);
- }
- return marqueeRectangleFigure;
- }
-
- protected Rectangle getMarqueeSelectionRectangle() {
- return new Rectangle(getStartLocation(), getLocation());
- }
-
- /**
- * Gets the relative bounds of the marquee feedback figure.
- *
- * @return
- */
- private Rectangle getMarqueeBounds() {
- if (getMarqueeFeedbackFigure() == null) {
- return new Rectangle();
- }
- Rectangle rect = new Rectangle();
- if (feedBackStartLocation == null) {
- rect = getMarqueeSelectionRectangle();
- getMarqueeFeedbackFigure().translateToRelative(rect);
- feedBackStartLocation = rect.getLocation();
- return rect;
- } else {
- Point location = getLocation().getCopy();
- getMarqueeFeedbackFigure().translateToRelative(location);
- rect = new Rectangle(feedBackStartLocation, location);
- return rect;
- }
-
- }
-
- private int getSelectionMode() {
- return mode;
- }
-
- protected Request getTargetRequest() {
- if (targetRequest == null) {
- targetRequest = createTargetRequest();
- }
- return targetRequest;
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#handleButtonDown(int)
- */
- @Override
- protected boolean handleButtonDown(int button) {
- if (!isGraphicalViewer()) {
- return true;
- }
- if (button != 1) {
- setState(STATE_INVALID);
- handleInvalidInput();
- }
- if (stateTransition(STATE_INITIAL, STATE_DRAG_IN_PROGRESS)) {
- if (getCurrentInput().isControlKeyDown()) {
- setSelectionMode(TOGGLE_MODE);
- } else if (getCurrentInput().isShiftKeyDown()) {
- setSelectionMode(APPEND_MODE);
- }
-
- // RATLC00740277:
- // clear current focus (if any) before we start computing selections,
- // because we don't want to select any compartments in the focus
- // edit part if they shouldn't be selectable
- clearFocus();
- }
- return true;
- }
-
- /**
- * Effectively clears the current focus edit part by deliberately setting the
- * diagram contents edit part as the focus. This ensures that the rubber band
- * won't mistakenly select the selectable compartments and items in the current
- * focus edit part.
- */
- private void clearFocus() {
- EditPart focusPart = getCurrentViewer().getFocusEditPart();
-
- if (focusPart != null) {
- // replace the current focus with the contents edit part, which effectively
- // blocks unwanted selectability of compartments within the previous
- // focus edit part
- getCurrentViewer().setFocus(getCurrentViewer().getContents());
- }
- }
-
- /**
- * Extends the inherited method by first restoring the current viewer's focus
- * edit part to the default (which is the last selected edit part). This undoes
- * the work-around that sets the diagram root as the focus.
- *
- * @see #clearFocus()
- */
- @Override
- protected void handleFinished() {
- getCurrentViewer().setFocus(null);
-
- super.handleFinished();
- }
-
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
- */
- @Override
- protected boolean handleButtonUp(int button) {
- if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
- eraseTargetFeedback();
- performMarqueeSelect();
- eraseMarqueeFeedback();
- }
- handleFinished();
- return true;
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#handleDragInProgress()
- */
- @Override
- protected boolean handleDragInProgress() {
- if (isInState(STATE_DRAG | STATE_DRAG_IN_PROGRESS)) {
-
- showMarqueeFeedback();
- eraseTargetFeedback();
- selectedEditParts = calculateNewSelection();
- showTargetFeedback();
- SelectInDiagramHelper.exposeLocation((FigureCanvas) getCurrentViewer().getControl(), getLocation());
-
- }
- return true;
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#handleFocusLost()
- */
- @Override
- protected boolean handleFocusLost() {
- if (isInState(STATE_DRAG | STATE_DRAG_IN_PROGRESS)) {
- handleFinished();
- return true;
- }
- return false;
- }
-
- /**
- * This method is called when mouse or keyboard input is invalid and erases the feedback.
- *
- * @return <code>true</code>
- */
- @Override
- protected boolean handleInvalidInput() {
- eraseTargetFeedback();
- eraseMarqueeFeedback();
- return true;
- }
-
- /**
- * Handles high-level processing of a key down event.
- * KeyEvents are forwarded to the current viewer's {@link KeyHandler},
- * via {@link KeyHandler#keyPressed(KeyEvent)}.
- *
- * @see AbstractTool#handleKeyDown(KeyEvent)
- */
- @Override
- protected boolean handleKeyDown(KeyEvent e) {
- if (super.handleKeyDown(e)) {
- return true;
- }
- if (getCurrentViewer().getKeyHandler() != null && getCurrentViewer().getKeyHandler().keyPressed(e)) {
- return true;
- }
- return false;
- }
-
- private boolean isGraphicalViewer() {
- return getCurrentViewer() instanceof GraphicalViewer;
- }
-
- protected void performMarqueeSelect() {
- EditPartViewer viewer = getCurrentViewer();
-
- List newSelections = calculateNewSelection();
-
- // If in multi select mode, add the new selections to the already
- // selected group; otherwise, clear the selection and select the new group
- if (getSelectionMode() == APPEND_MODE) {
- for (int i = 0; i < newSelections.size(); i++) {
- EditPart editPart = (EditPart) newSelections.get(i);
- viewer.appendSelection(editPart);
- }
- } else if (getSelectionMode() == TOGGLE_MODE) {
- List selected = new ArrayList(viewer.getSelectedEditParts());
- for (int i = 0; i < newSelections.size(); i++) {
- EditPart editPart = (EditPart) newSelections.get(i);
- if (editPart.getSelected() != EditPart.SELECTED_NONE) {
- selected.remove(editPart);
- } else {
- selected.add(editPart);
- }
- }
- viewer.setSelection(new StructuredSelection(selected));
- } else {
- viewer.setSelection(new StructuredSelection(newSelections));
- }
- }
-
- /**
- * @see org.eclipse.gef.Tool#setViewer(org.eclipse.gef.EditPartViewer)
- */
- @Override
- public void setViewer(EditPartViewer viewer) {
- if (viewer == getCurrentViewer()) {
- return;
- }
- super.setViewer(viewer);
- // If cursor is over a Graphical editor it will be a cross to indicate that the selectionTool is a Marquee tool
- if (viewer instanceof GraphicalViewer) {
- setDefaultCursor(Cursors.CROSS);
- } else {
- setDefaultCursor(Cursors.NO);
- }
- if (viewer != null) {
- weakReference = new WeakReference(viewer);
- }
- }
-
- private void setSelectionMode(int mode) {
- this.mode = mode;
- }
-
- private void showMarqueeFeedback() {
- getMarqueeFeedbackFigure().setBounds(getMarqueeBounds());
- }
-
- protected void showTargetFeedback() {
- for (int i = 0; i < selectedEditParts.size(); i++) {
- EditPart editPart = selectedEditParts.get(i);
- editPart.showTargetFeedback(getTargetRequest());
- }
- }
-
- /**
- * Convenience method to removes a figure from the feedback layer.
- *
- * @param figure
- * the figure being removed
- */
- @Override
- protected void removeFeedback(IFigure figure) {
- EditPartViewer viewer = getCurrentViewer();
- if ((viewer == null) && (weakReference != null)) {
- viewer = (EditPartViewer) weakReference.get();
- }
- if (viewer != null) {
- LayerManager lm = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
- if (lm == null) {
- return;
- }
- lm.getLayer(LayerConstants.FEEDBACK_LAYER).remove(figure);
- }
- }
-
- // create Marquee figure
- class MarqueeRectangleFigure extends Figure {
-
- private int offset = 0;
-
- private boolean schedulePaint = true;
-
- private static final int DELAY = 110; // animation delay in millisecond
-
- /**
- * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
- */
- @Override
- protected void paintFigure(Graphics graphics) {
- Rectangle graphicBounds = getBounds().getCopy();
- graphics.translate(getLocation());
-
- graphics.setXORMode(true);
- graphics.setForegroundColor(ColorConstants.white);
- graphics.setBackgroundColor(ColorConstants.black);
-
- graphics.setLineStyle(Graphics.LINE_DOT);
-
- int[] points = new int[6];
-
- points[0] = 0 + offset;
- points[1] = 0;
- points[2] = graphicBounds.width - 1;
- points[3] = 0;
- points[4] = graphicBounds.width - 1;
- points[5] = graphicBounds.height - 1;
-
- graphics.drawPolyline(points);
-
- points[0] = 0;
- points[1] = 0 + offset;
- points[2] = 0;
- points[3] = graphicBounds.height - 1;
- points[4] = graphicBounds.width - 1;
- points[5] = graphicBounds.height - 1;
-
- graphics.drawPolyline(points);
-
- graphics.translate(getLocation().getNegated());
-
- if (schedulePaint) {
- Display.getCurrent().timerExec(DELAY, new Runnable() {
-
- @Override
- public void run() {
- offset++;
- if (offset > 5) {
- offset = 0;
- }
- schedulePaint = true;
- repaint();
- }
- });
- }
-
- schedulePaint = false;
- }
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Céline Janssens - inspired by IBM class RubberbandSelectionTool : modify the calculateNewSelection method and add constructors
+ *
+ ****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.selection;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Set;
+
+import javax.swing.plaf.basic.BasicComboBoxUI.KeyHandler;
+
+import org.eclipse.draw2d.ColorConstants;
+import org.eclipse.draw2d.Connection;
+import org.eclipse.draw2d.Cursors;
+import org.eclipse.draw2d.Figure;
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.Graphics;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.GraphicalViewer;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.editparts.LayerManager;
+import org.eclipse.gef.tools.AbstractTool;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.LabelEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.ShapeEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.util.SelectInDiagramHelper;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * A Tool which selects multiple objects inside a rectangular area of a Graphical Viewer.<br/>
+ * If the SHIFT key is pressed at the beginning of the drag, the enclosed items will be
+ * appended to the current selection.<br/>
+ * If the CONTROL key is pressed at the beginning of
+ * the drag, the enclosed items will have their selection state inverted.
+ * <P>
+ * This tool is inspired from RubberbandSelectionTool to add some features.
+ * <li>Labels , affixed child nodes and connections are part of the eligible Edit Parts to be selected</li>
+ * <li>Additional constructors allow to select which behavior and which kind of editParts will be part of the selection</li>
+ * <li>Additional members allow to select which behavior and which kind of editParts are part of the selection</li>
+ * <li>Even the not visible EditParts inside of a container (due to scroll bars) will be part of selection</li>
+ */
+public class PapyrusRubberbandSelectionTool extends AbstractTool {
+
+ /**
+ * Mode in case of CTRL modifier key.
+ */
+ static final int TOGGLE_MODE = 1;
+
+ /**
+ * Mode in case of SHIFT modifier key.
+ */
+ static final int APPEND_MODE = 2;
+
+ private int mode;
+
+ private Figure marqueeRectangleFigure;
+
+ private Set<EditPart> allChildren = new HashSet<EditPart>();
+
+ private List<EditPart> selectedEditParts;
+
+ private Request targetRequest;
+
+ private Point feedBackStartLocation = null;
+
+ private WeakReference<?> weakReference;
+
+ private static final Request MARQUEE_REQUEST = new Request(RequestConstants.REQ_SELECTION);
+
+ /**
+ * Standard Marquee Selection behavior.
+ */
+ public static final int BEHAVIOR_OBJECT_INCLUDED = new Integer(1).intValue();
+
+ /**
+ * Rubberband Marquee Selection behavior.
+ */
+ public static final int BEHAVIOR_OBJECT_TOUCHED = new Integer(2).intValue();
+
+ /**
+ * Default Marquee Selection behavior.
+ */
+ public static final int DEFAULT_MARQUEE_BEHAVIOR = BEHAVIOR_OBJECT_INCLUDED;
+
+
+ private int marqueeBehavior = DEFAULT_MARQUEE_BEHAVIOR;
+
+ /**
+ * Define if the nodes should be part of the selection by default
+ */
+ public static final boolean DEFAULT_SELECT_NODES = true;
+
+ /**
+ * Define if the Labels should be part of the selection by default
+ */
+ public static final boolean DEFAULT_SELECT_LABELS = true;
+
+ /**
+ * Define if the Connections should be part of the selection by default
+ */
+ public static final boolean DEFAULT_SELECT_CONNECTIONS = true;
+
+ /**
+ * Parameter to define if Nodes should be part of the selection
+ */
+ private boolean selectNodes = DEFAULT_SELECT_NODES;
+
+ /**
+ * Parameter to define if Labels should be part of the selection
+ */
+ private boolean selectLabels = DEFAULT_SELECT_LABELS;
+
+ /**
+ * Parameter to define if Connections should be part of the selection
+ */
+ private boolean selectConnections = DEFAULT_SELECT_CONNECTIONS;
+
+
+ /**
+ * Constructor.
+ * Creates a new MarqueeSelectionTool.
+ */
+ public PapyrusRubberbandSelectionTool() {
+ setDefaultCursor(Cursors.CROSS);
+ setUnloadWhenFinished(false);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param behavior
+ * <li>BEHAVIOR_OBJECT_INCLUDE = 1</li> <li>BEHAVIOR_OBJECT_TOUCHED = 2</li>
+ */
+ public PapyrusRubberbandSelectionTool(int behavior) {
+ this();
+ this.setMarqueeBehavior(behavior);
+ }
+
+
+ /**
+ * Constructor.
+ *
+ * @param behavior
+ * Define what behavior is expected by the tool.
+ *
+ * <li>BEHAVIOR_OBJECT_INCLUDE = 1</li> <li>BEHAVIOR_OBJECT_TOUCHED = 2</li>
+ * @param nodeSelectable
+ * true if Nodes should be selected
+ * @param labelSelectable
+ * true if Labels should be selected
+ * @param connectionSelectable
+ * true if Connections should be selected
+ */
+ public PapyrusRubberbandSelectionTool(int behavior, boolean nodeSelectable, boolean labelSelectable, boolean connectionSelectable) {
+ this(behavior);
+
+ this.setSelectNodes(nodeSelectable);
+ this.setSelectLabels(labelSelectable);
+ this.setSelectConnections(connectionSelectable);
+
+ }
+
+ /**
+ * Defines if Nodes must be part of the selection
+ *
+ * @return selectNodes
+ */
+ public boolean isSelectNodes() {
+ return selectNodes;
+ }
+
+ /**
+ * Set if the Nodes should be part of the selection.
+ *
+ * @param selectNodes
+ */
+ public void setSelectNodes(boolean selectNodes) {
+ this.selectNodes = selectNodes;
+ }
+
+ /**
+ * Defines if Labels must be part of the selection
+ *
+ * @return selectLabels
+ */
+ public boolean isSelectLabels() {
+ return selectLabels;
+ }
+
+ /**
+ * Set if the Labels should be part of the selection.
+ *
+ * @param selectLabels
+ */
+ public void setSelectLabels(boolean selectLabels) {
+ this.selectLabels = selectLabels;
+ }
+
+
+
+ /**
+ * Defines if Connection must be part of the selection
+ *
+ * @return selectNodes
+ */
+ public boolean isSelectConnections() {
+ return selectConnections;
+ }
+
+ /**
+ * Set if the Connections should be part of the selection.
+ *
+ * @param selectConnections
+ */
+ public void setSelectConnections(boolean selectConnections) {
+ this.selectConnections = selectConnections;
+ }
+
+
+ /**
+ * Calculate the selection of the Rubberband: <li>List all the eligible Edit parts</li> <li>Keep only if include in the Marquee rectangle</li> <li>
+ * Add in the selection if the EditPart type (connection, Label and node) is requested into the selection</li>
+ *
+ * @return List of EditParts which meet the conditions of the selection
+ */
+ private List calculateNewSelection() {
+
+ List<EditPart> newSelections = new ArrayList<EditPart>();
+ Iterator<EditPart> children = getAllChildren().iterator();
+
+ // Calculate new selections based on which children fall
+ // inside the marquee selection rectangle.
+ // Select Nodes, Labels and Connections
+ while (children.hasNext()) {
+
+ EditPart child = children.next();
+
+ if (!child.isSelectable() || child.getTargetEditPart(MARQUEE_REQUEST) != child) {
+ continue;
+ }
+
+ // if the child is part of the Marquee selection add it to the list of selected EditParts
+ if (isPartOfMarqueeSelection(marqueeBehavior, child)) {
+
+ // if the child is a node and the nodes must be selected then add the child to the selection
+ if (isNode(child) && isSelectNodes()) {
+ newSelections.add(child);
+ } else if (isLabel(child) && isSelectLabels()) {
+ newSelections.add(child);
+ } else if (isConnection(child) && isSelectConnections()) {
+ newSelections.add(child);
+ } else {
+ continue;
+ }
+ }
+ }
+
+ return newSelections;
+ }
+
+ /**
+ * Check if an edit Part is a Node
+ *
+ * @return
+ */
+ private boolean isNode(EditPart editPart) {
+
+ return (editPart instanceof ShapeEditPart);
+ }
+
+
+ /**
+ * Check if an edit Part is a Label
+ *
+ * @return
+ */
+ private boolean isLabel(EditPart editPart) {
+
+ return (editPart instanceof LabelEditPart);
+ }
+
+
+ /**
+ * Check if an edit Part is a Connection
+ *
+ * @return
+ */
+ private boolean isConnection(EditPart editPart) {
+
+ return (editPart instanceof ConnectionEditPart);
+ }
+
+ /**
+ * Calculate if the editPart should be part of the selection depending on the wished marquee behavior.
+ *
+ * @param marqueeBehavior
+ * wished behavior for the selection (BEHAVIOR_OBJECT_INCLUDED, BEHAVIOR_OBJECT_TOUCHED, ...)
+ * @param editPart
+ * EditPart for which the selection is calculated
+ *
+ * @return <b>true</b> if the editPart is part of the selection.
+ */
+ private boolean isPartOfMarqueeSelection(int marqueeBehaviorType, EditPart editPart) {
+
+
+ boolean isInside = false;
+ boolean isTouched = false;
+ boolean isPartOfSelection = false;
+
+ IFigure figure = ((GraphicalEditPart) editPart).getFigure();
+ Rectangle marqueeBounds = getMarqueeBounds();
+
+ Rectangle figureRectangle;
+ if (editPart instanceof ConnectionEditPart) {
+ // RATLC00569348 For connection, get the bounds of connection points rather than connection figure since the
+ // figure's bounds contain the bounds of all connection editParts and would require selection rectangle
+ // to be larger than expected in some cases
+ figureRectangle = ((Connection) figure).getPoints().getBounds().getCopy();
+ } else {
+ figureRectangle = figure.getBounds().getCopy();
+ }
+ figure.translateToAbsolute(figureRectangle);
+ getMarqueeFeedbackFigure().translateToRelative(figureRectangle);
+
+ // If the objects are included into the Marquee Rectangle
+ isInside = (marqueeBounds.contains(figureRectangle.getTopLeft()) && marqueeBounds.contains(figureRectangle.getBottomRight()));
+
+ // If the objects are intersected by the Marquee Rectangle
+ isTouched = isTouchedByMarquee(marqueeBounds, figureRectangle);
+
+ if (marqueeBehaviorType == BEHAVIOR_OBJECT_INCLUDED) {
+ // Part of the selection only if inside
+ isPartOfSelection = isInside;
+
+ } else if (marqueeBehaviorType == BEHAVIOR_OBJECT_TOUCHED) {
+ // Part of the selection if inside or touched by the marquee
+ isPartOfSelection = isInside || isTouched;
+
+ }
+ return isPartOfSelection;
+
+ }
+
+ /**
+ * Define if the EditPart intersects the marquee rectangle.
+ *
+ * @param marqueeBounds
+ * The Marquee rectangle
+ * @param figureBounds
+ * The EditPart Figure Rectangle
+ * @return true if the intersection is not null
+ */
+ private boolean isTouchedByMarquee(Rectangle marqueeBounds, Rectangle figureBounds) {
+ // return true if the intersection is not null
+ return figureBounds.intersects(marqueeBounds);
+
+ }
+
+
+ /**
+ * Default getter of the Marquee Behavior
+ *
+ * @return behavior: <li>BEHAVIOR_OBJECT_INCLUDE = 1</li> <li>BEHAVIOR_OBJECT_TOUCHED = 2</li>
+ */
+ public int getMarqueeBehavior() {
+ return marqueeBehavior;
+ }
+
+ /**
+ * Default setter
+ *
+ * @param marqueeBehavior
+ */
+ public void setMarqueeBehavior(int marqueeBehavior) {
+ this.marqueeBehavior = marqueeBehavior;
+ }
+
+
+ protected Request createTargetRequest() {
+ return MARQUEE_REQUEST;
+ }
+
+ /**
+ * Erases feedback if necessary and puts the tool into the terminal state.
+ */
+ @Override
+ public void deactivate() {
+ if (isInState(STATE_DRAG_IN_PROGRESS)) {
+ eraseMarqueeFeedback();
+ eraseTargetFeedback();
+ }
+ super.deactivate();
+ allChildren = new HashSet<EditPart>();
+ setState(STATE_TERMINAL);
+ }
+
+ private void eraseMarqueeFeedback() {
+ if (marqueeRectangleFigure != null) {
+ removeFeedback(marqueeRectangleFigure);
+ marqueeRectangleFigure = null;
+ }
+ feedBackStartLocation = null;
+ }
+
+ protected void eraseTargetFeedback() {
+ if (selectedEditParts == null) {
+ return;
+ }
+ ListIterator<EditPart> oldEditParts = selectedEditParts.listIterator();
+ while (oldEditParts.hasNext()) {
+ EditPart editPart = oldEditParts.next();
+ editPart.eraseTargetFeedback(getTargetRequest());
+ }
+ }
+
+
+
+ /**
+ * Returns a list including all of the children
+ * of the edit part passed in.
+ */
+ private HashSet<EditPart> getAllChildren(EditPart editPart, HashSet<EditPart> currentSelection) {
+
+ // List all the editPart children
+ List<EditPart> children = editPart.getChildren();
+
+ // for each child, add the child and all its connections to the currentSelection
+ for (int i = 0; i < children.size(); i++) {
+
+ GraphicalEditPart child = (GraphicalEditPart) children.get(i);
+
+ currentSelection.add(child);
+
+ getAllChildren(child, currentSelection);
+
+ List sourceConnections = child.getSourceConnections();
+ List targetConnections = child.getTargetConnections();
+
+
+ // Add all the connection and they children into the List of all the Objects to be selected
+ // Connection children are all its labels
+ for (int j = 0; j < sourceConnections.size(); j++) {
+
+ // Add the connection
+ currentSelection.add((GraphicalEditPart) sourceConnections.get(j));
+ // Add the connection children (Labels)
+ getAllChildren((EditPart) sourceConnections.get(j), currentSelection);
+ }
+
+ // Add all the connection and they children into the List of all the Objects to be selected
+ for (int k = 0; k < targetConnections.size(); k++) {
+
+ // Add the connection
+ currentSelection.add((GraphicalEditPart) targetConnections.get(k));
+ // Add the connection children (Labels)
+ getAllChildren((EditPart) targetConnections.get(k), currentSelection);
+
+ }
+
+ }
+
+
+ return currentSelection;
+ }
+
+ /**
+ * Return a vector including all of the children
+ * of the root editpart
+ */
+ private Set<EditPart> getAllChildren() {
+ if (allChildren.isEmpty()) {
+ allChildren = getAllChildren(getCurrentViewer().getContents(), new HashSet<EditPart>());
+ }
+ return allChildren;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
+ */
+ @Override
+ protected String getCommandName() {
+ return REQ_SELECTION;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
+ */
+ @Override
+ protected String getDebugName() {
+ return "Marquee Tool";//$NON-NLS-1$
+ }
+
+ protected IFigure getMarqueeFeedbackFigure() {
+ if (marqueeRectangleFigure == null) {
+ marqueeRectangleFigure = new MarqueeRectangleFigure();
+ addFeedback(marqueeRectangleFigure);
+ }
+ return marqueeRectangleFigure;
+ }
+
+ protected Rectangle getMarqueeSelectionRectangle() {
+ return new Rectangle(getStartLocation(), getLocation());
+ }
+
+ /**
+ * Gets the relative bounds of the marquee feedback figure.
+ *
+ * @return
+ */
+ private Rectangle getMarqueeBounds() {
+ if (getMarqueeFeedbackFigure() == null) {
+ return new Rectangle();
+ }
+ Rectangle rect = new Rectangle();
+ if (feedBackStartLocation == null) {
+ rect = getMarqueeSelectionRectangle();
+ getMarqueeFeedbackFigure().translateToRelative(rect);
+ feedBackStartLocation = rect.getLocation();
+ return rect;
+ } else {
+ Point location = getLocation().getCopy();
+ getMarqueeFeedbackFigure().translateToRelative(location);
+ rect = new Rectangle(feedBackStartLocation, location);
+ return rect;
+ }
+
+ }
+
+ private int getSelectionMode() {
+ return mode;
+ }
+
+ protected Request getTargetRequest() {
+ if (targetRequest == null) {
+ targetRequest = createTargetRequest();
+ }
+ return targetRequest;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#handleButtonDown(int)
+ */
+ @Override
+ protected boolean handleButtonDown(int button) {
+ if (!isGraphicalViewer()) {
+ return true;
+ }
+ if (button != 1) {
+ setState(STATE_INVALID);
+ handleInvalidInput();
+ }
+ if (stateTransition(STATE_INITIAL, STATE_DRAG_IN_PROGRESS)) {
+ if (getCurrentInput().isControlKeyDown()) {
+ setSelectionMode(TOGGLE_MODE);
+ } else if (getCurrentInput().isShiftKeyDown()) {
+ setSelectionMode(APPEND_MODE);
+ }
+
+ // RATLC00740277:
+ // clear current focus (if any) before we start computing selections,
+ // because we don't want to select any compartments in the focus
+ // edit part if they shouldn't be selectable
+ clearFocus();
+ }
+ return true;
+ }
+
+ /**
+ * Effectively clears the current focus edit part by deliberately setting the
+ * diagram contents edit part as the focus. This ensures that the rubber band
+ * won't mistakenly select the selectable compartments and items in the current
+ * focus edit part.
+ */
+ private void clearFocus() {
+ EditPart focusPart = getCurrentViewer().getFocusEditPart();
+
+ if (focusPart != null) {
+ // replace the current focus with the contents edit part, which effectively
+ // blocks unwanted selectability of compartments within the previous
+ // focus edit part
+ getCurrentViewer().setFocus(getCurrentViewer().getContents());
+ }
+ }
+
+ /**
+ * Extends the inherited method by first restoring the current viewer's focus
+ * edit part to the default (which is the last selected edit part). This undoes
+ * the work-around that sets the diagram root as the focus.
+ *
+ * @see #clearFocus()
+ */
+ @Override
+ protected void handleFinished() {
+ getCurrentViewer().setFocus(null);
+
+ super.handleFinished();
+ }
+
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
+ */
+ @Override
+ protected boolean handleButtonUp(int button) {
+ if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
+ eraseTargetFeedback();
+ performMarqueeSelect();
+ eraseMarqueeFeedback();
+ }
+ handleFinished();
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#handleDragInProgress()
+ */
+ @Override
+ protected boolean handleDragInProgress() {
+ if (isInState(STATE_DRAG | STATE_DRAG_IN_PROGRESS)) {
+
+ showMarqueeFeedback();
+ eraseTargetFeedback();
+ selectedEditParts = calculateNewSelection();
+ showTargetFeedback();
+ SelectInDiagramHelper.exposeLocation((FigureCanvas) getCurrentViewer().getControl(), getLocation());
+
+ }
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#handleFocusLost()
+ */
+ @Override
+ protected boolean handleFocusLost() {
+ if (isInState(STATE_DRAG | STATE_DRAG_IN_PROGRESS)) {
+ handleFinished();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * This method is called when mouse or keyboard input is invalid and erases the feedback.
+ *
+ * @return <code>true</code>
+ */
+ @Override
+ protected boolean handleInvalidInput() {
+ eraseTargetFeedback();
+ eraseMarqueeFeedback();
+ return true;
+ }
+
+ /**
+ * Handles high-level processing of a key down event.
+ * KeyEvents are forwarded to the current viewer's {@link KeyHandler},
+ * via {@link KeyHandler#keyPressed(KeyEvent)}.
+ *
+ * @see AbstractTool#handleKeyDown(KeyEvent)
+ */
+ @Override
+ protected boolean handleKeyDown(KeyEvent e) {
+ if (super.handleKeyDown(e)) {
+ return true;
+ }
+ if (getCurrentViewer().getKeyHandler() != null && getCurrentViewer().getKeyHandler().keyPressed(e)) {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean isGraphicalViewer() {
+ return getCurrentViewer() instanceof GraphicalViewer;
+ }
+
+ protected void performMarqueeSelect() {
+ EditPartViewer viewer = getCurrentViewer();
+
+ List newSelections = calculateNewSelection();
+
+ // If in multi select mode, add the new selections to the already
+ // selected group; otherwise, clear the selection and select the new group
+ if (getSelectionMode() == APPEND_MODE) {
+ for (int i = 0; i < newSelections.size(); i++) {
+ EditPart editPart = (EditPart) newSelections.get(i);
+ viewer.appendSelection(editPart);
+ }
+ } else if (getSelectionMode() == TOGGLE_MODE) {
+ List selected = new ArrayList(viewer.getSelectedEditParts());
+ for (int i = 0; i < newSelections.size(); i++) {
+ EditPart editPart = (EditPart) newSelections.get(i);
+ if (editPart.getSelected() != EditPart.SELECTED_NONE) {
+ selected.remove(editPart);
+ } else {
+ selected.add(editPart);
+ }
+ }
+ viewer.setSelection(new StructuredSelection(selected));
+ } else {
+ viewer.setSelection(new StructuredSelection(newSelections));
+ }
+ }
+
+ /**
+ * @see org.eclipse.gef.Tool#setViewer(org.eclipse.gef.EditPartViewer)
+ */
+ @Override
+ public void setViewer(EditPartViewer viewer) {
+ if (viewer == getCurrentViewer()) {
+ return;
+ }
+ super.setViewer(viewer);
+ // If cursor is over a Graphical editor it will be a cross to indicate that the selectionTool is a Marquee tool
+ if (viewer instanceof GraphicalViewer) {
+ setDefaultCursor(Cursors.CROSS);
+ } else {
+ setDefaultCursor(Cursors.NO);
+ }
+ if (viewer != null) {
+ weakReference = new WeakReference(viewer);
+ }
+ }
+
+ private void setSelectionMode(int mode) {
+ this.mode = mode;
+ }
+
+ private void showMarqueeFeedback() {
+ getMarqueeFeedbackFigure().setBounds(getMarqueeBounds());
+ }
+
+ protected void showTargetFeedback() {
+ for (int i = 0; i < selectedEditParts.size(); i++) {
+ EditPart editPart = selectedEditParts.get(i);
+ editPart.showTargetFeedback(getTargetRequest());
+ }
+ }
+
+ /**
+ * Convenience method to removes a figure from the feedback layer.
+ *
+ * @param figure
+ * the figure being removed
+ */
+ @Override
+ protected void removeFeedback(IFigure figure) {
+ EditPartViewer viewer = getCurrentViewer();
+ if ((viewer == null) && (weakReference != null)) {
+ viewer = (EditPartViewer) weakReference.get();
+ }
+ if (viewer != null) {
+ LayerManager lm = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
+ if (lm == null) {
+ return;
+ }
+ lm.getLayer(LayerConstants.FEEDBACK_LAYER).remove(figure);
+ }
+ }
+
+ // create Marquee figure
+ class MarqueeRectangleFigure extends Figure {
+
+ private int offset = 0;
+
+ private boolean schedulePaint = true;
+
+ private static final int DELAY = 110; // animation delay in millisecond
+
+ /**
+ * @see org.eclipse.draw2d.Figure#paintFigure(org.eclipse.draw2d.Graphics)
+ */
+ @Override
+ protected void paintFigure(Graphics graphics) {
+ Rectangle graphicBounds = getBounds().getCopy();
+ graphics.translate(getLocation());
+
+ graphics.setXORMode(true);
+ graphics.setForegroundColor(ColorConstants.white);
+ graphics.setBackgroundColor(ColorConstants.black);
+
+ graphics.setLineStyle(Graphics.LINE_DOT);
+
+ int[] points = new int[6];
+
+ points[0] = 0 + offset;
+ points[1] = 0;
+ points[2] = graphicBounds.width - 1;
+ points[3] = 0;
+ points[4] = graphicBounds.width - 1;
+ points[5] = graphicBounds.height - 1;
+
+ graphics.drawPolyline(points);
+
+ points[0] = 0;
+ points[1] = 0 + offset;
+ points[2] = 0;
+ points[3] = graphicBounds.height - 1;
+ points[4] = graphicBounds.width - 1;
+ points[5] = graphicBounds.height - 1;
+
+ graphics.drawPolyline(points);
+
+ graphics.translate(getLocation().getNegated());
+
+ if (schedulePaint) {
+ Display.getCurrent().timerExec(DELAY, new Runnable() {
+
+ @Override
+ public void run() {
+ offset++;
+ if (offset > 5) {
+ offset = 0;
+ }
+ schedulePaint = true;
+ repaint();
+ }
+ });
+ }
+
+ schedulePaint = false;
+ }
+
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/SelectionToolPaletteFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/SelectionToolPaletteFactory.java
index d860ad226a0..a4feb816431 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/SelectionToolPaletteFactory.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/selection/SelectionToolPaletteFactory.java
@@ -1,132 +1,132 @@
-/*****************************************************************************
- * Copyright (c) 2012, 2014 CEA LIST.
- *
- * 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:
- *
- * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - initial API and implementation
- *
- ****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.selection;
-
-import org.eclipse.gef.Tool;
-import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteFactory;
-
-
-/**
- * This Factory creates the different selection tools of the Palette depending on the wished behavior.
- *
- * <p>
- * There are 2 types of behaviors for the marquee selection:
- * <li>Rubberband : Select the items intersected or included into the marquee rectangle</li>
- * <li>Inside : Select the items completely included into the marquee rectangle</li>
- * </p>
- * <br/>
- * On top of this 2 different behaviors, the tool can define if labels, connectors or nodes are part of the selection Tool.
- * By default they are all part of the selection.
- * This factory creates 8 tools combining those criteria.<br/>
- *
- * @author Céline JANSSENS
- *
- */
-public class SelectionToolPaletteFactory extends PaletteFactory.Adapter {
-
-
- private static final String TOOL_SELECTION_RUBBERBAND = "selectionRubberband"; //$NON-NLS-1$
-
- private static final String TOOL_SELECTION_RUBBERBAND_NODE = "selectionRubberbandNodeOnly"; //$NON-NLS-1$
-
- private static final String TOOL_SELECTION_RUBBERBAND_CONNECTION = "selectionRubberbandConnectionOnly"; //$NON-NLS-1$
-
- private static final String TOOL_SELECTION_RUBBERBAND_LABEL = "selectionRubberbandLabelOnly"; //$NON-NLS-1$
-
-
-
- private static final String TOOL_SELECTION_INSIDE = "selectionInside"; //$NON-NLS-1$
-
- private static final String TOOL_SELECTION_INSIDE_NODE = "selectionInsideNodeOnly"; //$NON-NLS-1$
-
- private static final String TOOL_SELECTION_INSIDE_CONNECTION = "selectionInsideConnectionOnly"; //$NON-NLS-1$
-
- private static final String TOOL_SELECTION_INSIDE_LABEL = "selectionInsideLabelOnly"; //$NON-NLS-1$
-
-
-
- @Override
- public Tool createTool(String toolId) {
-
- // Rubberband with all item
- if (toolId.equals(TOOL_SELECTION_RUBBERBAND)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
- return tool;
-
- // Standard Marquee Selection with all item
- } else if (toolId.equals(TOOL_SELECTION_INSIDE)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
- return tool;
-
- // Rubberband with only Nodes
- } else if (toolId.equals(TOOL_SELECTION_RUBBERBAND_NODE)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
- tool.setSelectLabels(false);
- tool.setSelectNodes(true);
- tool.setSelectConnections(false);
- return tool;
-
- // Rubberband with only Connection
- } else if (toolId.equals(TOOL_SELECTION_RUBBERBAND_CONNECTION)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
- tool.setSelectLabels(false);
- tool.setSelectNodes(false);
- tool.setSelectConnections(true);
- return tool;
-
- // Rubberband with only Labels
- } else if (toolId.equals(TOOL_SELECTION_RUBBERBAND_LABEL)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
- tool.setSelectLabels(true);
- tool.setSelectNodes(false);
- tool.setSelectConnections(false);
- return tool;
-
- // Standard marquee with only Nodes
- } else if (toolId.equals(TOOL_SELECTION_INSIDE_NODE)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
- tool.setSelectLabels(false);
- tool.setSelectNodes(true);
- tool.setSelectConnections(false);
- return tool;
-
- // Standard marquee with only Labels
- } else if (toolId.equals(TOOL_SELECTION_INSIDE_LABEL)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
- tool.setSelectLabels(true);
- tool.setSelectNodes(false);
- tool.setSelectConnections(false);
- return tool;
-
- // Standard marquee with only Connections
- } else if (toolId.equals(TOOL_SELECTION_INSIDE_CONNECTION)) {
- PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
- tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
- tool.setSelectLabels(false);
- tool.setSelectNodes(false);
- tool.setSelectConnections(true);
- return tool;
-
- }
-
- return super.createTool(toolId);
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012, 2014 CEA LIST.
+ *
+ * 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:
+ *
+ * Céline Janssens (ALL4TEC) celine.janssens@all4tec.net - initial API and implementation
+ *
+ ****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.selection;
+
+import org.eclipse.gef.Tool;
+import org.eclipse.gmf.runtime.diagram.ui.services.palette.PaletteFactory;
+
+
+/**
+ * This Factory creates the different selection tools of the Palette depending on the wished behavior.
+ *
+ * <p>
+ * There are 2 types of behaviors for the marquee selection:
+ * <li>Rubberband : Select the items intersected or included into the marquee rectangle</li>
+ * <li>Inside : Select the items completely included into the marquee rectangle</li>
+ * </p>
+ * <br/>
+ * On top of this 2 different behaviors, the tool can define if labels, connectors or nodes are part of the selection Tool.
+ * By default they are all part of the selection.
+ * This factory creates 8 tools combining those criteria.<br/>
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public class SelectionToolPaletteFactory extends PaletteFactory.Adapter {
+
+
+ private static final String TOOL_SELECTION_RUBBERBAND = "selectionRubberband"; //$NON-NLS-1$
+
+ private static final String TOOL_SELECTION_RUBBERBAND_NODE = "selectionRubberbandNodeOnly"; //$NON-NLS-1$
+
+ private static final String TOOL_SELECTION_RUBBERBAND_CONNECTION = "selectionRubberbandConnectionOnly"; //$NON-NLS-1$
+
+ private static final String TOOL_SELECTION_RUBBERBAND_LABEL = "selectionRubberbandLabelOnly"; //$NON-NLS-1$
+
+
+
+ private static final String TOOL_SELECTION_INSIDE = "selectionInside"; //$NON-NLS-1$
+
+ private static final String TOOL_SELECTION_INSIDE_NODE = "selectionInsideNodeOnly"; //$NON-NLS-1$
+
+ private static final String TOOL_SELECTION_INSIDE_CONNECTION = "selectionInsideConnectionOnly"; //$NON-NLS-1$
+
+ private static final String TOOL_SELECTION_INSIDE_LABEL = "selectionInsideLabelOnly"; //$NON-NLS-1$
+
+
+
+ @Override
+ public Tool createTool(String toolId) {
+
+ // Rubberband with all item
+ if (toolId.equals(TOOL_SELECTION_RUBBERBAND)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
+ return tool;
+
+ // Standard Marquee Selection with all item
+ } else if (toolId.equals(TOOL_SELECTION_INSIDE)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
+ return tool;
+
+ // Rubberband with only Nodes
+ } else if (toolId.equals(TOOL_SELECTION_RUBBERBAND_NODE)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
+ tool.setSelectLabels(false);
+ tool.setSelectNodes(true);
+ tool.setSelectConnections(false);
+ return tool;
+
+ // Rubberband with only Connection
+ } else if (toolId.equals(TOOL_SELECTION_RUBBERBAND_CONNECTION)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
+ tool.setSelectLabels(false);
+ tool.setSelectNodes(false);
+ tool.setSelectConnections(true);
+ return tool;
+
+ // Rubberband with only Labels
+ } else if (toolId.equals(TOOL_SELECTION_RUBBERBAND_LABEL)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_TOUCHED);
+ tool.setSelectLabels(true);
+ tool.setSelectNodes(false);
+ tool.setSelectConnections(false);
+ return tool;
+
+ // Standard marquee with only Nodes
+ } else if (toolId.equals(TOOL_SELECTION_INSIDE_NODE)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
+ tool.setSelectLabels(false);
+ tool.setSelectNodes(true);
+ tool.setSelectConnections(false);
+ return tool;
+
+ // Standard marquee with only Labels
+ } else if (toolId.equals(TOOL_SELECTION_INSIDE_LABEL)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
+ tool.setSelectLabels(true);
+ tool.setSelectNodes(false);
+ tool.setSelectConnections(false);
+ return tool;
+
+ // Standard marquee with only Connections
+ } else if (toolId.equals(TOOL_SELECTION_INSIDE_CONNECTION)) {
+ PapyrusRubberbandSelectionTool tool = new PapyrusRubberbandSelectionTool();
+ tool.setMarqueeBehavior(PapyrusRubberbandSelectionTool.BEHAVIOR_OBJECT_INCLUDED);
+ tool.setSelectLabels(false);
+ tool.setSelectNodes(false);
+ tool.setSelectConnections(true);
+ return tool;
+
+ }
+
+ return super.createTool(toolId);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/WorkspaceExtendedPaletteProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/WorkspaceExtendedPaletteProvider.java
index 8e0cc42420e..787d37a281d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/WorkspaceExtendedPaletteProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/palette/WorkspaceExtendedPaletteProvider.java
@@ -1,66 +1,66 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST.
- *
- * 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:
- * Remi Schnekenburger (CEA LIST) - Initial API and implementation
- * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - bug 512343
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.palette;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
-import org.eclipse.papyrus.infra.gmfdiag.common.messages.Messages;
-import org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration.Activator;
-import org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration.PaletteConfiguration;
-import org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration.PaletteconfigurationPackage;
-
-/**
- * Palette provider to be used for palettes defined by models, when they are located in the workspace (deployment at runtime)
- */
-public class WorkspaceExtendedPaletteProvider extends ExtendedPluginPaletteProvider implements IPaletteProvider {
-
- protected boolean loadResourceExceptionLogged = false;
-
- /**
- * locally defines palette
- *
- * @param description
- * the description of the palette to build
- */
- public void setContributions(IPaletteDescription description) {
- ResourceSet resourceSet = new ResourceSetImpl();
- Object paletteContributions = description.getContributions();
- contributions = Collections.emptyList();
- if (!(paletteContributions instanceof String)) {
- return;
- }
- Resource resource = loadResourceFromWorkspace((String) paletteContributions, resourceSet);
- if (resource != null) {
- try {
- resource.load(Collections.emptyMap());
- if (resource.getContents().size() > 0) {
- contributions = new ArrayList<PaletteConfiguration>(EcoreUtil.<PaletteConfiguration> getObjectsByType(resource.getContents(), PaletteconfigurationPackage.eINSTANCE.getPaletteConfiguration()));
- }
- } catch (IOException e) {
- if (!loadResourceExceptionLogged) {
- Activator.log.debug(Messages.WorkspaceExtendedPaletteProvider_ImpossibleToReadResourcePalette + description);
- loadResourceExceptionLogged = true;
- }
- contributions = Collections.emptyList();
- }
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) - Initial API and implementation
+ * Mickaël ADAM (ALL4TEC) mickael.adam@all4tec.net - bug 512343
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.palette;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gmf.runtime.diagram.ui.services.palette.IPaletteProvider;
+import org.eclipse.papyrus.infra.gmfdiag.common.messages.Messages;
+import org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration.Activator;
+import org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration.PaletteConfiguration;
+import org.eclipse.papyrus.infra.gmfdiag.paletteconfiguration.PaletteconfigurationPackage;
+
+/**
+ * Palette provider to be used for palettes defined by models, when they are located in the workspace (deployment at runtime)
+ */
+public class WorkspaceExtendedPaletteProvider extends ExtendedPluginPaletteProvider implements IPaletteProvider {
+
+ protected boolean loadResourceExceptionLogged = false;
+
+ /**
+ * locally defines palette
+ *
+ * @param description
+ * the description of the palette to build
+ */
+ public void setContributions(IPaletteDescription description) {
+ ResourceSet resourceSet = new ResourceSetImpl();
+ Object paletteContributions = description.getContributions();
+ contributions = Collections.emptyList();
+ if (!(paletteContributions instanceof String)) {
+ return;
+ }
+ Resource resource = loadResourceFromWorkspace((String) paletteContributions, resourceSet);
+ if (resource != null) {
+ try {
+ resource.load(Collections.emptyMap());
+ if (resource.getContents().size() > 0) {
+ contributions = new ArrayList<PaletteConfiguration>(EcoreUtil.<PaletteConfiguration> getObjectsByType(resource.getContents(), PaletteconfigurationPackage.eINSTANCE.getPaletteConfiguration()));
+ }
+ } catch (IOException e) {
+ if (!loadResourceExceptionLogged) {
+ Activator.log.debug(Messages.WorkspaceExtendedPaletteProvider_ImpossibleToReadResourcePalette + description);
+ loadResourceExceptionLogged = true;
+ }
+ contributions = Collections.emptyList();
+ }
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
index bb0960fef93..555f65cfdd5 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/AbstractShapeProvider.java
@@ -1,346 +1,346 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
-import org.apache.batik.dom.util.DOMUtilities;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
-import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
-import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
-import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory;
-import org.eclipse.papyrus.commands.Activator;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-import org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart;
-import org.eclipse.papyrus.infra.gmfdiag.common.handler.RefreshHandler;
-import org.eclipse.papyrus.infra.gmfdiag.common.utils.PositionEnum;
-import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
-import org.eclipse.ui.IEditorPart;
-import org.w3c.dom.Document;
-import org.w3c.dom.svg.SVGDocument;
-
-/**
- * Abstract implementation of the shape provider interface.
- */
-public abstract class AbstractShapeProvider extends AbstractProvider implements IShapeProvider, IRefreshHandlerPart {
-
- /** Prefix for platform strings */
- protected static final String PLATFORM = "platform:/"; //$NON-NLS-1$
-
- /**
- * "Magic" key within an SVG filename for orientation dependent files
- */
- protected static final String POSITION_KEY = "position"; //$NON-NLS-1$
-
- /** field for name */
- protected static final String NAME = "name"; //$NON-NLS-1$
-
- /** field for identifier */
- protected static final String ID = "id"; //$NON-NLS-1$
-
- /** field for description */
- protected static final String DESCRIPTION = "description"; //$NON-NLS-1$
-
- /** field for Activator ID */
- protected String bundleId;
-
- /** name for the factory */
- protected String name;
-
- /** identifier for the factory */
- protected String id;
-
- /** description of the factory */
- protected String description;
-
- /**
- * Maps of URIs for SVG files referred to with relative paths
- */
- private WeakHashMap<Resource, Map<String, String>> relativePaths;
-
- /** Cache for the loaded SVG document */
- private Map<String, SVGDocument> cache;
-
-
- /**
- * Initializes this provider
- */
- public AbstractShapeProvider() {
- RefreshHandler.register(this);
- }
-
- /**
- * Returns the bundle identifier for this provider
- *
- * @return the bundle identifier for this provider
- */
- public String getBundleId() {
- return bundleId;
- }
-
-
- /**
- * Returns the name of this provider
- *
- * @return the name of this provider
- */
- public String getName() {
- return name;
- }
-
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getId() {
- return id;
- }
-
-
- /**
- * Returns the description of this provider
- *
- * @return the description of this provider
- */
- public String getDescription() {
- return description;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public boolean provides(IOperation operation) {
- return operation instanceof GetAllShapeProvidersOperation || operation instanceof GetShapeProviderByIdentifierOperation;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setConfiguration(IConfigurationElement element) {
- name = element.getAttribute(NAME);
- id = element.getAttribute(ID);
- description = element.getAttribute(DESCRIPTION);
- bundleId = element.getContributor().getName();
- }
-
- /**
- * Loads a SVG document from the given location.
- * This method uses a cache so that any given document is only loaded once.
- *
- * @param view
- * The view object to retrieve a svg document for
- * @param location
- * The location to load the document from
- * @return the Document SVG from its location, can return null if this is not a svg
- */
- protected synchronized SVGDocument getSVGDocument(EObject view, String location) {
- if (relativePaths == null) {
- relativePaths = new WeakHashMap<Resource, Map<String, String>>();
- }
- if (location.contains("/" + POSITION_KEY) || location.contains("." + POSITION_KEY)) { //$NON-NLS-1$//$NON-NLS-2$
- // load a specific variant of a symbol (with a different orientation) if the file name
- // contains a specific "magic" key. The motivation is that symbols on the border of a parent
- // (e.g. a port symbol) could always point into the parent shape depending on its position
- try {
- IMultiDiagramEditor editor = ServiceUtilsForEObject.getInstance().getService(IMultiDiagramEditor.class, view);
-
- IEditorPart part = editor.getActiveEditor();
- PositionEnum positionKey = PositionEnum.SOUTH;
- if (part instanceof DiagramEditor) {
- Map<?, ?> editPartRegistry = ((DiagramEditor) part).getDiagramGraphicalViewer().getEditPartRegistry();
- // get edit part, in order to retrieve a border item locator that is in turn used to obtain the
- // relative position
- EditPart ep = (EditPart) editPartRegistry.get(view);
- if (ep instanceof AbstractBorderItemEditPart) {
- IBorderItemLocator locator = ((AbstractBorderItemEditPart) ep).getBorderItemLocator();
- if (locator != null) {
- int side = locator.getCurrentSideOfParent();
- positionKey = getPositionKey(side);
- }
- }
- }
- location = location.replace(POSITION_KEY, positionKey.getLiteral());
- } catch (ServiceException e) {
- Activator.log.error(e);
- }
- }
-
- String canonical = getCanonicalURI(view, location);
- return getSVGDocument(canonical);
- }
-
- /**
- * Get a position key (enumeration) from the bit-vector representation of the position
- * @param side the binary encoded position
- * @return the position key
- */
- protected PositionEnum getPositionKey(int side) {
- if ((side & PositionConstants.WEST) > 0) {
- return PositionEnum.WEST;
- } else if ((side & PositionConstants.EAST) > 0) {
- return PositionEnum.EAST;
- } else if ((side & PositionConstants.NORTH) > 0) {
- return PositionEnum.NORTH;
- } else {
- // use south as default
- return PositionEnum.SOUTH;
- }
- }
- /**
- * Loads a SVG document from the given location.
- * This method uses a cache so that any given document is only loaded once.
- *
- * @param location
- * The location to load the document from
- * @return the Document SVG from its location, can return null if this is not a svg
- */
- protected synchronized SVGDocument getSVGDocument(String location) {
- if (cache == null) {
- cache = new HashMap<String, SVGDocument>();
- }
- if (cache.containsKey(location)) {
- return cache.get(location);
- }
- SVGDocument doc = doGetSVGDocument(location);
- cache.put(location, doc);
- return doc;
- }
-
- /**
- * Loads a SVG document from the given location
- *
- * @param location
- * The location to load the document from
- * @return the Document SVG from its location, can return null if this is not a svg
- */
- private SVGDocument doGetSVGDocument(String location) {
- int extensionIndex = location.lastIndexOf('.');
- if (extensionIndex <= 0) {
- return null;
- }
- String fileExtension = location.substring(extensionIndex);
- if (!fileExtension.equalsIgnoreCase(".svg")) { //$NON-NLS-1$
- return null;
- }
-
- String parser = org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName();
-
- try {
- SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
-
- Document doc = f.createDocument(location);
- SVGDocument svgDocument = (SVGDocument) doc;
- return svgDocument;
-
- } catch (Exception e) {
- org.eclipse.papyrus.infra.core.Activator.log.error(e);
- }
- return null;
- }
-
- /**
- * Translates the given URI as a string to a canonical Eclipse URI
- * The URI may be relative to the currently edited EMF resource
- *
- * @param model
- * The model element used to retrieve the EMF resource that is currently edited
- * @param uri
- * The potentially relative URI of a svg file
- * @return The canonical URI of the resource
- */
- private String getCanonicalURI(EObject model, String uri) {
- if (uri.startsWith(PLATFORM)) {
- return uri;
- }
-
- Map<String, String> resMap = relativePaths.get(model.eResource());
- if (resMap == null) {
- resMap = new HashMap<String, String>();
- relativePaths.put(model.eResource(), resMap);
- }
- String canonical = resMap.get(uri);
- if (canonical != null) {
- return canonical;
- }
-
- URI resURI = model.eResource().getURI();
- if (!resURI.isPlatform()) {
- return null;
- }
- StringBuilder builder = new StringBuilder(PLATFORM);
- String[] segments = resURI.segments();
- for (int i = 0; i < segments.length - 1; i++) {
- builder.append(segments[i]);
- builder.append("/"); //$NON-NLS-1$
- }
- builder.append(uri);
- canonical = builder.toString();
- resMap.put(uri, canonical);
- return canonical;
- }
-
- protected RenderedImage renderSVGDocument(EObject view, SVGDocument document) throws IOException {
- postProcess(view, document);
- String svgAsText = toString(document);
- byte[] buffer = svgAsText.getBytes();
-
- return RenderedImageFactory.getInstance(buffer);
- }
-
- protected void postProcess(EObject view, SVGDocument document) {
- SVGPostProcessor.instance.postProcess(view, document);
- }
-
- protected String toString(SVGDocument domDocument) throws IOException {
- StringWriter writer = new StringWriter();
-
- DOMUtilities.writeDocument(domDocument, writer);
-
- return writer.toString();
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart#refresh(org.eclipse.ui.IEditorPart)
- */
- @Override
- public synchronized void refresh(IEditorPart editorPart) {
- // Clears the cache of loaded SVG documents
- // This will force their reloading
- if (cache != null) {
- cache.clear();
- }
- if (relativePaths != null) {
- relativePaths.clear();
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
+import org.apache.batik.dom.util.DOMUtilities;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.figures.IBorderItemLocator;
+import org.eclipse.gmf.runtime.diagram.ui.parts.DiagramEditor;
+import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
+import org.eclipse.gmf.runtime.draw2d.ui.render.factory.RenderedImageFactory;
+import org.eclipse.papyrus.commands.Activator;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart;
+import org.eclipse.papyrus.infra.gmfdiag.common.handler.RefreshHandler;
+import org.eclipse.papyrus.infra.gmfdiag.common.utils.PositionEnum;
+import org.eclipse.papyrus.infra.ui.editor.IMultiDiagramEditor;
+import org.eclipse.ui.IEditorPart;
+import org.w3c.dom.Document;
+import org.w3c.dom.svg.SVGDocument;
+
+/**
+ * Abstract implementation of the shape provider interface.
+ */
+public abstract class AbstractShapeProvider extends AbstractProvider implements IShapeProvider, IRefreshHandlerPart {
+
+ /** Prefix for platform strings */
+ protected static final String PLATFORM = "platform:/"; //$NON-NLS-1$
+
+ /**
+ * "Magic" key within an SVG filename for orientation dependent files
+ */
+ protected static final String POSITION_KEY = "position"; //$NON-NLS-1$
+
+ /** field for name */
+ protected static final String NAME = "name"; //$NON-NLS-1$
+
+ /** field for identifier */
+ protected static final String ID = "id"; //$NON-NLS-1$
+
+ /** field for description */
+ protected static final String DESCRIPTION = "description"; //$NON-NLS-1$
+
+ /** field for Activator ID */
+ protected String bundleId;
+
+ /** name for the factory */
+ protected String name;
+
+ /** identifier for the factory */
+ protected String id;
+
+ /** description of the factory */
+ protected String description;
+
+ /**
+ * Maps of URIs for SVG files referred to with relative paths
+ */
+ private WeakHashMap<Resource, Map<String, String>> relativePaths;
+
+ /** Cache for the loaded SVG document */
+ private Map<String, SVGDocument> cache;
+
+
+ /**
+ * Initializes this provider
+ */
+ public AbstractShapeProvider() {
+ RefreshHandler.register(this);
+ }
+
+ /**
+ * Returns the bundle identifier for this provider
+ *
+ * @return the bundle identifier for this provider
+ */
+ public String getBundleId() {
+ return bundleId;
+ }
+
+
+ /**
+ * Returns the name of this provider
+ *
+ * @return the name of this provider
+ */
+ public String getName() {
+ return name;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getId() {
+ return id;
+ }
+
+
+ /**
+ * Returns the description of this provider
+ *
+ * @return the description of this provider
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public boolean provides(IOperation operation) {
+ return operation instanceof GetAllShapeProvidersOperation || operation instanceof GetShapeProviderByIdentifierOperation;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void setConfiguration(IConfigurationElement element) {
+ name = element.getAttribute(NAME);
+ id = element.getAttribute(ID);
+ description = element.getAttribute(DESCRIPTION);
+ bundleId = element.getContributor().getName();
+ }
+
+ /**
+ * Loads a SVG document from the given location.
+ * This method uses a cache so that any given document is only loaded once.
+ *
+ * @param view
+ * The view object to retrieve a svg document for
+ * @param location
+ * The location to load the document from
+ * @return the Document SVG from its location, can return null if this is not a svg
+ */
+ protected synchronized SVGDocument getSVGDocument(EObject view, String location) {
+ if (relativePaths == null) {
+ relativePaths = new WeakHashMap<Resource, Map<String, String>>();
+ }
+ if (location.contains("/" + POSITION_KEY) || location.contains("." + POSITION_KEY)) { //$NON-NLS-1$//$NON-NLS-2$
+ // load a specific variant of a symbol (with a different orientation) if the file name
+ // contains a specific "magic" key. The motivation is that symbols on the border of a parent
+ // (e.g. a port symbol) could always point into the parent shape depending on its position
+ try {
+ IMultiDiagramEditor editor = ServiceUtilsForEObject.getInstance().getService(IMultiDiagramEditor.class, view);
+
+ IEditorPart part = editor.getActiveEditor();
+ PositionEnum positionKey = PositionEnum.SOUTH;
+ if (part instanceof DiagramEditor) {
+ Map<?, ?> editPartRegistry = ((DiagramEditor) part).getDiagramGraphicalViewer().getEditPartRegistry();
+ // get edit part, in order to retrieve a border item locator that is in turn used to obtain the
+ // relative position
+ EditPart ep = (EditPart) editPartRegistry.get(view);
+ if (ep instanceof AbstractBorderItemEditPart) {
+ IBorderItemLocator locator = ((AbstractBorderItemEditPart) ep).getBorderItemLocator();
+ if (locator != null) {
+ int side = locator.getCurrentSideOfParent();
+ positionKey = getPositionKey(side);
+ }
+ }
+ }
+ location = location.replace(POSITION_KEY, positionKey.getLiteral());
+ } catch (ServiceException e) {
+ Activator.log.error(e);
+ }
+ }
+
+ String canonical = getCanonicalURI(view, location);
+ return getSVGDocument(canonical);
+ }
+
+ /**
+ * Get a position key (enumeration) from the bit-vector representation of the position
+ * @param side the binary encoded position
+ * @return the position key
+ */
+ protected PositionEnum getPositionKey(int side) {
+ if ((side & PositionConstants.WEST) > 0) {
+ return PositionEnum.WEST;
+ } else if ((side & PositionConstants.EAST) > 0) {
+ return PositionEnum.EAST;
+ } else if ((side & PositionConstants.NORTH) > 0) {
+ return PositionEnum.NORTH;
+ } else {
+ // use south as default
+ return PositionEnum.SOUTH;
+ }
+ }
+ /**
+ * Loads a SVG document from the given location.
+ * This method uses a cache so that any given document is only loaded once.
+ *
+ * @param location
+ * The location to load the document from
+ * @return the Document SVG from its location, can return null if this is not a svg
+ */
+ protected synchronized SVGDocument getSVGDocument(String location) {
+ if (cache == null) {
+ cache = new HashMap<String, SVGDocument>();
+ }
+ if (cache.containsKey(location)) {
+ return cache.get(location);
+ }
+ SVGDocument doc = doGetSVGDocument(location);
+ cache.put(location, doc);
+ return doc;
+ }
+
+ /**
+ * Loads a SVG document from the given location
+ *
+ * @param location
+ * The location to load the document from
+ * @return the Document SVG from its location, can return null if this is not a svg
+ */
+ private SVGDocument doGetSVGDocument(String location) {
+ int extensionIndex = location.lastIndexOf('.');
+ if (extensionIndex <= 0) {
+ return null;
+ }
+ String fileExtension = location.substring(extensionIndex);
+ if (!fileExtension.equalsIgnoreCase(".svg")) { //$NON-NLS-1$
+ return null;
+ }
+
+ String parser = org.apache.batik.util.XMLResourceDescriptor.getXMLParserClassName();
+
+ try {
+ SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
+
+ Document doc = f.createDocument(location);
+ SVGDocument svgDocument = (SVGDocument) doc;
+ return svgDocument;
+
+ } catch (Exception e) {
+ org.eclipse.papyrus.infra.core.Activator.log.error(e);
+ }
+ return null;
+ }
+
+ /**
+ * Translates the given URI as a string to a canonical Eclipse URI
+ * The URI may be relative to the currently edited EMF resource
+ *
+ * @param model
+ * The model element used to retrieve the EMF resource that is currently edited
+ * @param uri
+ * The potentially relative URI of a svg file
+ * @return The canonical URI of the resource
+ */
+ private String getCanonicalURI(EObject model, String uri) {
+ if (uri.startsWith(PLATFORM)) {
+ return uri;
+ }
+
+ Map<String, String> resMap = relativePaths.get(model.eResource());
+ if (resMap == null) {
+ resMap = new HashMap<String, String>();
+ relativePaths.put(model.eResource(), resMap);
+ }
+ String canonical = resMap.get(uri);
+ if (canonical != null) {
+ return canonical;
+ }
+
+ URI resURI = model.eResource().getURI();
+ if (!resURI.isPlatform()) {
+ return null;
+ }
+ StringBuilder builder = new StringBuilder(PLATFORM);
+ String[] segments = resURI.segments();
+ for (int i = 0; i < segments.length - 1; i++) {
+ builder.append(segments[i]);
+ builder.append("/"); //$NON-NLS-1$
+ }
+ builder.append(uri);
+ canonical = builder.toString();
+ resMap.put(uri, canonical);
+ return canonical;
+ }
+
+ protected RenderedImage renderSVGDocument(EObject view, SVGDocument document) throws IOException {
+ postProcess(view, document);
+ String svgAsText = toString(document);
+ byte[] buffer = svgAsText.getBytes();
+
+ return RenderedImageFactory.getInstance(buffer);
+ }
+
+ protected void postProcess(EObject view, SVGDocument document) {
+ SVGPostProcessor.instance.postProcess(view, document);
+ }
+
+ protected String toString(SVGDocument domDocument) throws IOException {
+ StringWriter writer = new StringWriter();
+
+ DOMUtilities.writeDocument(domDocument, writer);
+
+ return writer.toString();
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.handler.IRefreshHandlerPart#refresh(org.eclipse.ui.IEditorPart)
+ */
+ @Override
+ public synchronized void refresh(IEditorPart editorPart) {
+ // Clears the cache of loaded SVG documents
+ // This will force their reloading
+ if (cache != null) {
+ cache.clear();
+ }
+ if (relativePaths != null) {
+ relativePaths.clear();
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/CreateProviderNotificationManagersOperation.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/CreateProviderNotificationManagersOperation.java
index 17154104856..e76c874114e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/CreateProviderNotificationManagersOperation.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/CreateProviderNotificationManagersOperation.java
@@ -1,74 +1,74 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
-import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
-
-
-/**
- * Operation that ask the shape provider to add notification listeners to the interesting objects.
- */
-public class CreateProviderNotificationManagersOperation implements IOperation, IShapeProviderOperation {
-
- /** diagram event broker that dispatches the notifications to interested elements */
- private DiagramEventBroker diagramEventBroker;
-
- /** view from which objects to listen are retrieved */
- private EObject view;
-
- /** notification listener to be notified of modifications */
- private NotificationListener notificationListener;
-
- /**
- * Creates a new AddNotificationListenersOperation.
- *
- * @param diagramEventBroker
- * diagram event broker that dispatches the notifications to interested elements
- * @param view
- * view from which objects to listen are retrieved
- * @param notificationListener
- */
- public CreateProviderNotificationManagersOperation(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener notificationListener) {
- this.diagramEventBroker = diagramEventBroker;
- this.view = view;
- this.notificationListener = notificationListener;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object execute(IProvider provider) {
- if (provider instanceof IShapeProvider) {
- return ((IShapeProvider) provider).createProviderNotificationManager(getDiagramEventBroker(), getView(), getNotificationListener());
- }
- return null;
- }
-
- protected EObject getView() {
- return view;
- }
-
- protected DiagramEventBroker getDiagramEventBroker() {
- return diagramEventBroker;
- }
-
- protected NotificationListener getNotificationListener() {
- return notificationListener;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
+
+
+/**
+ * Operation that ask the shape provider to add notification listeners to the interesting objects.
+ */
+public class CreateProviderNotificationManagersOperation implements IOperation, IShapeProviderOperation {
+
+ /** diagram event broker that dispatches the notifications to interested elements */
+ private DiagramEventBroker diagramEventBroker;
+
+ /** view from which objects to listen are retrieved */
+ private EObject view;
+
+ /** notification listener to be notified of modifications */
+ private NotificationListener notificationListener;
+
+ /**
+ * Creates a new AddNotificationListenersOperation.
+ *
+ * @param diagramEventBroker
+ * diagram event broker that dispatches the notifications to interested elements
+ * @param view
+ * view from which objects to listen are retrieved
+ * @param notificationListener
+ */
+ public CreateProviderNotificationManagersOperation(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener notificationListener) {
+ this.diagramEventBroker = diagramEventBroker;
+ this.view = view;
+ this.notificationListener = notificationListener;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object execute(IProvider provider) {
+ if (provider instanceof IShapeProvider) {
+ return ((IShapeProvider) provider).createProviderNotificationManager(getDiagramEventBroker(), getView(), getNotificationListener());
+ }
+ return null;
+ }
+
+ protected EObject getView() {
+ return view;
+ }
+
+ protected DiagramEventBroker getDiagramEventBroker() {
+ return diagramEventBroker;
+ }
+
+ protected NotificationListener getNotificationListener() {
+ return notificationListener;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetAllShapeProvidersOperation.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetAllShapeProvidersOperation.java
index 8e1fbf4e6bf..b679fc7920d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetAllShapeProvidersOperation.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetAllShapeProvidersOperation.java
@@ -1,49 +1,49 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import java.util.List;
-
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-
-/**
- * Operation to find all shape providers
- */
-public class GetAllShapeProvidersOperation implements IOperation, IShapeProviderOperation {
-
- /** list of providers to complete */
- protected final List<IShapeProvider> providers;
-
- /**
- * Creates a new GetAllAspectToolProvidersOperation.
- */
- protected GetAllShapeProvidersOperation(List<IShapeProvider> providers) {
- this.providers = providers;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public Object execute(IProvider provider) {
- if (provider instanceof IShapeProvider) {
- providers.add((IShapeProvider) provider);
- } else {
- Activator.log.warn("Trying to add a non-shape provider to the list of shape providers");
- }
- return providers;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import java.util.List;
+
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+
+/**
+ * Operation to find all shape providers
+ */
+public class GetAllShapeProvidersOperation implements IOperation, IShapeProviderOperation {
+
+ /** list of providers to complete */
+ protected final List<IShapeProvider> providers;
+
+ /**
+ * Creates a new GetAllAspectToolProvidersOperation.
+ */
+ protected GetAllShapeProvidersOperation(List<IShapeProvider> providers) {
+ this.providers = providers;
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public Object execute(IProvider provider) {
+ if (provider instanceof IShapeProvider) {
+ providers.add((IShapeProvider) provider);
+ } else {
+ Activator.log.warn("Trying to add a non-shape provider to the list of shape providers");
+ }
+ return providers;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetSVGDocumentForViewOperation.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetSVGDocumentForViewOperation.java
index 810ebae8cd3..5e881622ab8 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetSVGDocumentForViewOperation.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetSVGDocumentForViewOperation.java
@@ -1,60 +1,60 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.w3c.dom.svg.SVGDocument;
-
-/**
- * Operation to find a list of shapes, given a view
- */
-public class GetSVGDocumentForViewOperation implements IOperation, IShapeProviderOperation {
-
- /** View from which shape has to be retrieved */
- private final EObject view;
-
- /**
- * Creates a new GetShapeProvidersForViewOperation.
- *
- * @param view
- * the EObject for which shapes has to be found
- */
- protected GetSVGDocumentForViewOperation(EObject view) {
- assert null != view : "GetDocumentForViewOperation constructor received NULL as argument"; //$NON-NLS-1$
- this.view = view;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public List<SVGDocument> execute(IProvider provider) {
- if (!(provider instanceof IShapeProvider)) {
- return null;
- }
- IShapeProvider shapeProvider = (IShapeProvider) provider;
- return shapeProvider.getSVGDocument(getView());
- }
-
- /**
- * Returns the view for which this operation is looking for shapes
- *
- * @return the view for which this operation is looking for shapes
- */
- protected EObject getView() {
- return view;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.w3c.dom.svg.SVGDocument;
+
+/**
+ * Operation to find a list of shapes, given a view
+ */
+public class GetSVGDocumentForViewOperation implements IOperation, IShapeProviderOperation {
+
+ /** View from which shape has to be retrieved */
+ private final EObject view;
+
+ /**
+ * Creates a new GetShapeProvidersForViewOperation.
+ *
+ * @param view
+ * the EObject for which shapes has to be found
+ */
+ protected GetSVGDocumentForViewOperation(EObject view) {
+ assert null != view : "GetDocumentForViewOperation constructor received NULL as argument"; //$NON-NLS-1$
+ this.view = view;
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public List<SVGDocument> execute(IProvider provider) {
+ if (!(provider instanceof IShapeProvider)) {
+ return null;
+ }
+ IShapeProvider shapeProvider = (IShapeProvider) provider;
+ return shapeProvider.getSVGDocument(getView());
+ }
+
+ /**
+ * Returns the view for which this operation is looking for shapes
+ *
+ * @return the view for which this operation is looking for shapes
+ */
+ protected EObject getView() {
+ return view;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapeProviderByIdentifierOperation.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapeProviderByIdentifierOperation.java
index d6ff9ad2199..34cc94973aa 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapeProviderByIdentifierOperation.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapeProviderByIdentifierOperation.java
@@ -1,54 +1,54 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * 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:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-
-/**
- * Operation to find a shape provider, given its unique identifier
- */
-public class GetShapeProviderByIdentifierOperation implements IOperation, IShapeProviderOperation {
-
- /** id of the action to retrieve */
- private final String identifier;
-
- /**
- * Creates a new GetShapeProviderOperation.
- *
- * @param identifier
- * the identifier of the operation to retrieve
- */
- protected GetShapeProviderByIdentifierOperation(String identifier) {
- assert null != identifier : "GetAspectToolOperation constructor received NULL as argument"; //$NON-NLS-1$
-
- this.identifier = identifier;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public IProvider execute(IProvider provider) {
- String id = ((IShapeProvider) provider).getId();
- return (identifier.equals(id) ? provider : null);
- }
-
- /**
- * Returns the identifier of the provider this operation is looking for
- *
- * @return the identifier of the provider this operation is looking for
- */
- public String getIdentifier() {
- return identifier;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+
+/**
+ * Operation to find a shape provider, given its unique identifier
+ */
+public class GetShapeProviderByIdentifierOperation implements IOperation, IShapeProviderOperation {
+
+ /** id of the action to retrieve */
+ private final String identifier;
+
+ /**
+ * Creates a new GetShapeProviderOperation.
+ *
+ * @param identifier
+ * the identifier of the operation to retrieve
+ */
+ protected GetShapeProviderByIdentifierOperation(String identifier) {
+ assert null != identifier : "GetAspectToolOperation constructor received NULL as argument"; //$NON-NLS-1$
+
+ this.identifier = identifier;
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public IProvider execute(IProvider provider) {
+ String id = ((IShapeProvider) provider).getId();
+ return (identifier.equals(id) ? provider : null);
+ }
+
+ /**
+ * Returns the identifier of the provider this operation is looking for
+ *
+ * @return the identifier of the provider this operation is looking for
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapesForViewOperation.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapesForViewOperation.java
index 9737a9d2e30..3ad582c7e71 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapesForViewOperation.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/GetShapesForViewOperation.java
@@ -1,60 +1,60 @@
-/*****************************************************************************
- * Copyright (c) 2010 CEA LIST.
- *
- * 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:
- * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.common.core.service.IOperation;
-import org.eclipse.gmf.runtime.common.core.service.IProvider;
-import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
-
-/**
- * Operation to find a list of shapes, given a view
- */
-public class GetShapesForViewOperation implements IOperation, IShapeProviderOperation {
-
- /** View from which shape has to be retrieved */
- private final EObject view;
-
- /**
- * Creates a new GetShapeProvidersForViewOperation.
- *
- * @param view
- * the EObject for which shapes has to be found
- */
- protected GetShapesForViewOperation(EObject view) {
- assert null != view : "GetShapesForViewOperation constructor received NULL as argument"; //$NON-NLS-1$
- this.view = view;
- }
-
- /**
- * @{inheritDoc
- */
- @Override
- public List<RenderedImage> execute(IProvider provider) {
- if (!(provider instanceof IShapeProvider)) {
- return null;
- }
- IShapeProvider shapeProvider = (IShapeProvider) provider;
- return shapeProvider.getShapes(getView());
- }
-
- /**
- * Returns the view for which this operation is looking for shapes
- *
- * @return the view for which this operation is looking for shapes
- */
- protected EObject getView() {
- return view;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010 CEA LIST.
+ *
+ * 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:
+ * Remi Schnekenburger (CEA LIST) remi.schnekenburger@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.common.core.service.IOperation;
+import org.eclipse.gmf.runtime.common.core.service.IProvider;
+import org.eclipse.gmf.runtime.draw2d.ui.render.RenderedImage;
+
+/**
+ * Operation to find a list of shapes, given a view
+ */
+public class GetShapesForViewOperation implements IOperation, IShapeProviderOperation {
+
+ /** View from which shape has to be retrieved */
+ private final EObject view;
+
+ /**
+ * Creates a new GetShapeProvidersForViewOperation.
+ *
+ * @param view
+ * the EObject for which shapes has to be found
+ */
+ protected GetShapesForViewOperation(EObject view) {
+ assert null != view : "GetShapesForViewOperation constructor received NULL as argument"; //$NON-NLS-1$
+ this.view = view;
+ }
+
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public List<RenderedImage> execute(IProvider provider) {
+ if (!(provider instanceof IShapeProvider)) {
+ return null;
+ }
+ IShapeProvider shapeProvider = (IShapeProvider) provider;
+ return shapeProvider.getShapes(getView());
+ }
+
+ /**
+ * Returns the view for which this operation is looking for shapes
+ *
+ * @return the view for which this operation is looking for shapes
+ */
+ protected EObject getView() {
+ return view;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/IShapeProviderOperation.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/IShapeProviderOperation.java
index 61a5bfca8b7..6fc5480ba6f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/IShapeProviderOperation.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/IShapeProviderOperation.java
@@ -1,21 +1,21 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-/**
- * Marker interface that all operations working for the shpae service should implement.
- */
-public interface IShapeProviderOperation {
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+/**
+ * Marker interface that all operations working for the shpae service should implement.
+ */
+public interface IShapeProviderOperation {
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/NotificationManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/NotificationManager.java
index ecf946f1d42..afda3fa83d4 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/NotificationManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/NotificationManager.java
@@ -1,78 +1,78 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-
-/**
- * Notification Manager for the Shape Service.
- * <P>
- * This manager will centralized for a given view all elements that have to be watched in order to react to changes.
- * </P>
- */
-public class NotificationManager {
-
- /** view that listens for modifications */
- private EObject view;
-
- /** list of provider notification manager */
- private List<ProviderNotificationManager> providerNotificationManagers;
-
- /**
- * Creates a new NotificationManager.
- *
- * @param view
- * the main object that have to listen for notifications
- */
- public NotificationManager(EObject view) {
- this.view = view;
- providerNotificationManagers = new ArrayList<ProviderNotificationManager>();
- }
-
- /**
- * Returns the view that listens for modifications
- *
- * @return the view that listens for modifications
- */
- public EObject getView() {
- return view;
- }
-
- /**
- * Returns the list of provider notification manager
- *
- * @return the providerNotificationManager
- */
- public List<ProviderNotificationManager> getProviderNotificationManagers() {
- return providerNotificationManagers;
- }
-
- /**
- * Makes the object ready for GC.
- */
- public void dispose() {
- // remove all listeners
- for (ProviderNotificationManager providerNotificationManager : getProviderNotificationManagers()) {
- if (providerNotificationManager != null) {
- providerNotificationManager.dispose();
- }
- }
- providerNotificationManagers.clear();
- providerNotificationManagers = null;
- view = null;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+
+/**
+ * Notification Manager for the Shape Service.
+ * <P>
+ * This manager will centralized for a given view all elements that have to be watched in order to react to changes.
+ * </P>
+ */
+public class NotificationManager {
+
+ /** view that listens for modifications */
+ private EObject view;
+
+ /** list of provider notification manager */
+ private List<ProviderNotificationManager> providerNotificationManagers;
+
+ /**
+ * Creates a new NotificationManager.
+ *
+ * @param view
+ * the main object that have to listen for notifications
+ */
+ public NotificationManager(EObject view) {
+ this.view = view;
+ providerNotificationManagers = new ArrayList<ProviderNotificationManager>();
+ }
+
+ /**
+ * Returns the view that listens for modifications
+ *
+ * @return the view that listens for modifications
+ */
+ public EObject getView() {
+ return view;
+ }
+
+ /**
+ * Returns the list of provider notification manager
+ *
+ * @return the providerNotificationManager
+ */
+ public List<ProviderNotificationManager> getProviderNotificationManagers() {
+ return providerNotificationManagers;
+ }
+
+ /**
+ * Makes the object ready for GC.
+ */
+ public void dispose() {
+ // remove all listeners
+ for (ProviderNotificationManager providerNotificationManager : getProviderNotificationManagers()) {
+ if (providerNotificationManager != null) {
+ providerNotificationManager.dispose();
+ }
+ }
+ providerNotificationManagers.clear();
+ providerNotificationManagers = null;
+ view = null;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ProviderNotificationManager.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ProviderNotificationManager.java
index b340f712df1..dffd2a2c10d 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ProviderNotificationManager.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ProviderNotificationManager.java
@@ -1,59 +1,59 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- *
- * 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:
- * Patrick Tessier (CEA LIST) - Initial API and implementation
- /*****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
-import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
-
-/**
- * Abstract notification manager for a given {@link IShapeProvider}.
- */
-public abstract class ProviderNotificationManager {
-
- protected DiagramEventBroker diagramEventBroker;
- protected EObject view;
- protected NotificationListener listener;
-
- /**
- * Creates a new ProviderNotificationManager.
- *
- * @param diagramEventBroker
- * event broker specific to the diargam displaying the shapes.
- * @param view
- * the view from which all elements to listen will be computed.
- * @param listener
- * the listener to which notifications will be forwarded.
- */
- public ProviderNotificationManager(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener listener) {
- this.diagramEventBroker = diagramEventBroker;
- this.view = view;
- this.listener = listener;
- registerListeners();
- }
-
- /**
- * Register all the required elements in the diagram event broker.
- */
- protected abstract void registerListeners();
-
- /**
- * Makes the object ready for GC.
- */
- public void dispose() {
- view = null;
- diagramEventBroker = null;
- listener = null;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ *
+ * 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:
+ * Patrick Tessier (CEA LIST) - Initial API and implementation
+ /*****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gmf.runtime.diagram.core.listener.DiagramEventBroker;
+import org.eclipse.gmf.runtime.diagram.core.listener.NotificationListener;
+
+/**
+ * Abstract notification manager for a given {@link IShapeProvider}.
+ */
+public abstract class ProviderNotificationManager {
+
+ protected DiagramEventBroker diagramEventBroker;
+ protected EObject view;
+ protected NotificationListener listener;
+
+ /**
+ * Creates a new ProviderNotificationManager.
+ *
+ * @param diagramEventBroker
+ * event broker specific to the diargam displaying the shapes.
+ * @param view
+ * the view from which all elements to listen will be computed.
+ * @param listener
+ * the listener to which notifications will be forwarded.
+ */
+ public ProviderNotificationManager(DiagramEventBroker diagramEventBroker, EObject view, NotificationListener listener) {
+ this.diagramEventBroker = diagramEventBroker;
+ this.view = view;
+ this.listener = listener;
+ registerListeners();
+ }
+
+ /**
+ * Register all the required elements in the diagram event broker.
+ */
+ protected abstract void registerListeners();
+
+ /**
+ * Makes the object ready for GC.
+ */
+ public void dispose() {
+ view = null;
+ diagramEventBroker = null;
+ listener = null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/SVGPostProcessor.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/SVGPostProcessor.java
index d05f421ef1e..bb6135c00d8 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/SVGPostProcessor.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/SVGPostProcessor.java
@@ -1,47 +1,47 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.w3c.dom.svg.SVGDocument;
-
-/**
- * A Post-Processor for SVG Documents
- *
- * Can be used to apply transformations before the SVGDocument is displayed on the diagram
- *
- * @author Camille Letavernier
- *
- */
-public interface SVGPostProcessor {
-
- public static final String EXTENSION_POINT = Activator.ID + ".svgPostProcessors";
-
- public static final String EXTENSION_CLASS_NAME_ATTRIBUTE = "implementation";
-
- /**
- * Singleton instance of the composite SVGPostProcessor. It aggregates all post-processors
- * declared via the {@link #EXTENSION_POINT} extension point
- */
- public SVGPostProcessor instance = new SVGPostProcessorImpl();
-
- /**
- * Apply a transformation on the given SVGDocument before it is rendered
- * The view can be used as the context of the transformation
- *
- * @param view
- * @param document
- */
- public void postProcess(EObject view, SVGDocument document);
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.w3c.dom.svg.SVGDocument;
+
+/**
+ * A Post-Processor for SVG Documents
+ *
+ * Can be used to apply transformations before the SVGDocument is displayed on the diagram
+ *
+ * @author Camille Letavernier
+ *
+ */
+public interface SVGPostProcessor {
+
+ public static final String EXTENSION_POINT = Activator.ID + ".svgPostProcessors";
+
+ public static final String EXTENSION_CLASS_NAME_ATTRIBUTE = "implementation";
+
+ /**
+ * Singleton instance of the composite SVGPostProcessor. It aggregates all post-processors
+ * declared via the {@link #EXTENSION_POINT} extension point
+ */
+ public SVGPostProcessor instance = new SVGPostProcessorImpl();
+
+ /**
+ * Apply a transformation on the given SVGDocument before it is rendered
+ * The view can be used as the context of the transformation
+ *
+ * @param view
+ * @param document
+ */
+ public void postProcess(EObject view, SVGDocument document);
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ShapeProviderConfiguration.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ShapeProviderConfiguration.java
index 962ea8e203a..549239a6b13 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ShapeProviderConfiguration.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/service/shape/ShapeProviderConfiguration.java
@@ -1,67 +1,67 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
-
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.gmf.runtime.common.core.service.AbstractProviderConfiguration;
-
-/**
- * Provider configuration for the shape provider extension point.
- */
-public class ShapeProviderConfiguration extends AbstractProviderConfiguration {
-
- /** field for identifier */
- protected static final String ID = "id";
-
- /** identifier of the factory */
- protected final String id;
-
- /**
- * Creates and builds a new provider contribution descriptor ( <code>ShapeProviderConfiguration</code>) by parsing its configuration
- * element.
- *
- * @param configElement
- * A provider XML configuration element
- * @return A provider XML contribution descriptor
- */
- public static ShapeProviderConfiguration parse(IConfigurationElement configElement) {
- Assert.isNotNull(configElement, "null provider configuration element"); //$NON-NLS-1$
- return new ShapeProviderConfiguration(configElement);
- }
-
- /**
- * Creates a new <code>ProviderContributionDescriptor</code> instance by
- * parsing its configuration element.
- *
- * @param configElement
- * The provider XML configuration element
- */
- protected ShapeProviderConfiguration(IConfigurationElement configElement) {
- // retrieve only ID, to test if the factory is the right one before
- // creating whole element
- id = configElement.getAttribute(ID);
- Assert.isNotNull(id, "impossible to get the identifier for the factory");
- }
-
- /**
- * Returns the ID of the factory configured by this configuration
- *
- * @return the id of the factory
- */
- public String getId() {
- return id;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.service.shape;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.gmf.runtime.common.core.service.AbstractProviderConfiguration;
+
+/**
+ * Provider configuration for the shape provider extension point.
+ */
+public class ShapeProviderConfiguration extends AbstractProviderConfiguration {
+
+ /** field for identifier */
+ protected static final String ID = "id";
+
+ /** identifier of the factory */
+ protected final String id;
+
+ /**
+ * Creates and builds a new provider contribution descriptor ( <code>ShapeProviderConfiguration</code>) by parsing its configuration
+ * element.
+ *
+ * @param configElement
+ * A provider XML configuration element
+ * @return A provider XML contribution descriptor
+ */
+ public static ShapeProviderConfiguration parse(IConfigurationElement configElement) {
+ Assert.isNotNull(configElement, "null provider configuration element"); //$NON-NLS-1$
+ return new ShapeProviderConfiguration(configElement);
+ }
+
+ /**
+ * Creates a new <code>ProviderContributionDescriptor</code> instance by
+ * parsing its configuration element.
+ *
+ * @param configElement
+ * The provider XML configuration element
+ */
+ protected ShapeProviderConfiguration(IConfigurationElement configElement) {
+ // retrieve only ID, to test if the factory is the right one before
+ // creating whole element
+ id = configElement.getAttribute(ID);
+ Assert.isNotNull(id, "impossible to get the identifier for the factory");
+ }
+
+ /**
+ * Returns the ID of the factory configured by this configuration
+ *
+ * @return the id of the factory
+ */
+ public String getId() {
+ return id;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/BorderNodeSnapHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/BorderNodeSnapHelper.java
index 3ec64202c79..c239ef61353 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/BorderNodeSnapHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/BorderNodeSnapHelper.java
@@ -1,36 +1,36 @@
-/*****************************************************************************
- * Copyright (c) 2014 CEA LIST.
- *
- * 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:
- * Vincent Lorenzo - CEA LIST
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.snap;
-
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.SnapToHelper;
-
-/**
- *
- * Snap Helper with default behavior for BorderNode (snap only on the center of the figrue
- * TODO PapyrusDragBorderNodeEditPartTrackerEx should use me
- */
-public class BorderNodeSnapHelper extends NodeSnapHelper {
-
- /**
- *
- * Constructor.
- *
- * @param helper
- * @param figureToSnapBounds
- */
- public BorderNodeSnapHelper(SnapToHelper helper, Rectangle figureToSnapBounds) {
- super(helper, figureToSnapBounds, false, false, true);
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2014 CEA LIST.
+ *
+ * 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:
+ * Vincent Lorenzo - CEA LIST
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.SnapToHelper;
+
+/**
+ *
+ * Snap Helper with default behavior for BorderNode (snap only on the center of the figrue
+ * TODO PapyrusDragBorderNodeEditPartTrackerEx should use me
+ */
+public class BorderNodeSnapHelper extends NodeSnapHelper {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param helper
+ * @param figureToSnapBounds
+ */
+ public BorderNodeSnapHelper(SnapToHelper helper, Rectangle figureToSnapBounds) {
+ super(helper, figureToSnapBounds, false, false, true);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/NodeSnapHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/NodeSnapHelper.java
index daf91f3130e..8596ad39a0a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/NodeSnapHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/NodeSnapHelper.java
@@ -1,459 +1,459 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Vincent Lorenzo - CEA LIST
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.snap;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.RootEditPart;
-import org.eclipse.gef.SnapToHelper;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.tools.DragEditPartsTracker;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
-
-/**
- *
- * this class allows to determine the best location for a node on the grid
- *
- * Adapted code from DragEditPartsTrackerEx
- * TODO : PapyrusDragEditPartTracker should use me
- */
-@SuppressWarnings("restriction")
-public class NodeSnapHelper {
-
- /**
- * if true, we snap on the four corner of the figures
- */
- protected final boolean snapOnCorners;
-
- /**
- * if true, we snap on the four middle side of the figures
- */
- protected final boolean snapOnMiddles;
-
- /**
- * if true, we snap on the center of the figure
- */
- protected final boolean snapOnCenter;
-
- /**
- * the snap helper to use
- */
- private SnapToHelper helper;
-
- /**
- * the bounds of the figure to snap
- */
- private Rectangle figureToSnapBounds;
-
- /**
- * the compoundSourceRectangle, see {@link DragEditPartsTracker} for further informations
- */
- private Rectangle compoundSourceRectangle;
-
- /**
- *
- * Constructor.
- *
- * @param helper
- * the snap helper
- * @param figureToSnapBounds
- * the bounds of the figure to snap
- *
- */
- public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds) {
- this(helper, figureToSnapBounds, figureToSnapBounds);
- }
-
- /**
- *
- * Constructor.
- *
- * @param helper
- * the snap helper
- * @param figureToSnapBounds
- * the bounds of the figure to snap
- * @param compoundSourceRectangle
- * see {@link DragEditPartsTracker} for further informations
- */
- public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds, final Rectangle compoundSourceRectangle) {
- this(helper, figureToSnapBounds, compoundSourceRectangle, true, false, false);
- }
-
- /**
- *
- * Constructor.
- *
- * @param helper
- * @param figureToSnapBounds
- * @param snapOnCorners
- * @param snapOnMiddles
- * @param snapOnCenter
- */
- public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds, final boolean snapOnCorners, final boolean snapOnMiddles, final boolean snapOnCenter) {
- this(helper, figureToSnapBounds, figureToSnapBounds, snapOnCorners, snapOnMiddles, snapOnCenter);
- }
-
- /**
- *
- * Constructor.
- *
- * @param helper
- * @param figureToSnapBounds
- * @param compoundSourceRectangle
- * @param snapOnCorners
- * @param snapOnMiddles
- * @param snapOnCenter
- */
- public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds, final Rectangle compoundSourceRectangle, final boolean snapOnCorners, final boolean snapOnMiddles, final boolean snapOnCenter) {
- this.helper = helper;
- this.figureToSnapBounds = figureToSnapBounds;
- this.compoundSourceRectangle = compoundSourceRectangle;
- this.snapOnCorners = snapOnCorners;
- this.snapOnMiddles = snapOnMiddles;
- this.snapOnCenter = snapOnCenter;
- }
-
- /**
- * This method can be overridden by clients to customize the snapping
- * behavior.
- *
- * @param request
- * the <code>ChangeBoundsRequest</code> from which the move delta
- * can be extracted and updated
- * We use <code>ChangeBoundsRequest</code> to be compatible with snap edit part tracker!
- */
- @SuppressWarnings({ "unchecked" })
- public void snapPoint(ChangeBoundsRequest request) {
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
-
- // test to know if we are moving using keyboard
- // TODO not useful here
- // if(!getCurrentInput().isAnyButtonDown()) {
- // calculateSnapPointFromArrowKey(request);
- // return;
- // }
- int restrictedDirection = 0;
- restrictedDirection = restrictedDirection | PositionConstants.EAST;
- restrictedDirection = restrictedDirection | PositionConstants.WEST;
- restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
- restrictedDirection = restrictedDirection | PositionConstants.NORTH;
- request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
-
- final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
- if (this.snapOnCorners) {
- distVSPoint.putAll(getCornerDistances(request));
- }
-
- if (this.snapOnMiddles) {
- distVSPoint.putAll(getMiddleDistances(request));
- }
-
- if (this.snapOnCenter) {
- distVSPoint.putAll(getCenterDistances(request));
- }
-
- final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
- if (distances.size() > 0) {
- double min = distances.get(0);
- for (int i = 1; i < distances.size() - 1; i++) {
- min = Math.min(min, distances.get(i));
- }
- request.setMoveDelta(distVSPoint.get(min));
- }
- }
- }
-
- /**
- *
- * @param request
- * a move request
- * @return
- * the restricted direction for the request
- */
- protected final int getRestrictedDirection(final ChangeBoundsRequest request) {
- int restrictedDirection = 0;
- final Point delta = request.getMoveDelta();
- if (delta.x > 0) {
- restrictedDirection = restrictedDirection | PositionConstants.EAST;
- restrictedDirection = restrictedDirection | PositionConstants.WEST;
- }
- if (delta.x < 0) {
- restrictedDirection = restrictedDirection | PositionConstants.EAST;
- restrictedDirection = restrictedDirection | PositionConstants.WEST;
- }
- if (delta.y > 0) {
- restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
- restrictedDirection = restrictedDirection | PositionConstants.NORTH;
- }
- if (delta.y < 0) {
- restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
- restrictedDirection = restrictedDirection | PositionConstants.NORTH;
- }
- return restrictedDirection;
- }
-
- /**
- *
- * @param request
- * the move request
- */
- @SuppressWarnings("unchecked")
- protected void calculateSnapPointFromArrowKey(final ChangeBoundsRequest request) {
- if (request.getEditParts().size() == 0) {
- return;
- }
- final Object ep = request.getEditParts().get(0);
- if (!(ep instanceof IGraphicalEditPart)) {
- return;
- }
- final RootEditPart root = ((IGraphicalEditPart) ep).getRoot();
- if (!(root instanceof DiagramRootEditPart)) {
- return;
- }
- final double gridSpacing = ((DiagramRootEditPart) root).getGridSpacing();
- int max = (int) (1 + gridSpacing);
- int restrictedDirection = getRestrictedDirection(request);
- final Point delta = request.getMoveDelta();
- final Point newDelta = new Point(0, 0);
- int newMove = 0;
- while (newMove < max) {
- newMove++;
- if (delta.x > 0) {
- newDelta.x = newMove + delta.x;
- }
- if (delta.x < 0) {
- newDelta.x = (-newMove) + delta.x;
- }
- if (delta.y > 0) {
- newDelta.y = newMove + delta.y;
- }
- if (delta.y < 0) {
- newDelta.y = (-newMove) + delta.y;
- }
- request.setMoveDelta(newDelta);
- request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
-
- final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
- if (this.snapOnCorners) {
- distVSPoint.putAll(getCornerDistances(request));
- }
-
- if (this.snapOnMiddles) {
- distVSPoint.putAll(getMiddleDistances(request));
- }
-
- if (this.snapOnCenter) {
- distVSPoint.putAll(getCenterDistances(request));
- }
-
- final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
- if (distances.size() > 0) {
- double min = distances.get(0);
- // We look for the minus distance
- for (int i = 1; i < distances.size() - 1; i++) {
- min = Math.min(min, distances.get(i));
- }
- final Point minPoint = distVSPoint.get(min);
- // the distance can't be null
- if (minPoint.x != 0 || minPoint.y != 0) {
- // the calculate move must be in the same direction than the keyboard move
- if (Integer.signum(minPoint.x) == Integer.signum(delta.x) && Integer.signum(minPoint.y) == Integer.signum(delta.y)) {
- request.setMoveDelta(distVSPoint.get(min));
- return;
- }
- }
- }
- }
- }
-
- /**
- *
- * @param request
- * @return
- * a map with the couple distance and delta point to anchor by the corner of the figure
- */
- protected Map<Double, PrecisionPoint> getCornerDistances(final ChangeBoundsRequest request) {
- final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
- final Point moveDelta = request.getMoveDelta();
- PrecisionRectangle jointRect = getCompoundSourceRectangle();
- jointRect.translate(moveDelta);
-
- // calculate the delta to anchor on the top left corner
- final PrecisionPoint topLeftCornerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectTopLeft = getSourceRectangle();
- baseRectTopLeft.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectTopLeft, jointRect }, topLeftCornerDelta);
-
- // calculate the delta to anchor on the top right corner
- final PrecisionPoint topRightCornerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectTopRight = getSourceRectangle();
- baseRectTopRight.setX(baseRectTopRight.x + baseRectTopRight.width);
- baseRectTopRight.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectTopRight, jointRect }, topRightCornerDelta);
-
- // calculate the delta to anchor on the bottom left corner
- final PrecisionPoint bottomLeftCornerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectBottomLeft = getSourceRectangle();
- baseRectBottomLeft.setY(baseRectBottomLeft.y + baseRectBottomLeft.height);
- baseRectBottomLeft.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectBottomLeft, jointRect }, bottomLeftCornerDelta);
-
- // calculate the delta to anchor on the bottom right corner
- final PrecisionPoint bottomRightCornerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectBottomRight = getSourceRectangle();
- baseRectBottomRight.setX(baseRectBottomRight.x + baseRectBottomRight.width);
- baseRectBottomRight.setY(baseRectBottomRight.y + baseRectBottomRight.height);
- baseRectBottomRight.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectBottomRight, jointRect }, bottomRightCornerDelta);
-
- final Point ref = baseRectTopLeft.getTopLeft();
- distVSPoints.put(distance(ref, topLeftCornerDelta), topLeftCornerDelta);
- // distVSPoints.put(distance(ref, topRightCornerDelta), topRightCornerDelta);
- // distVSPoints.put(distance(ref, bottomLeftCornerDelta), bottomLeftCornerDelta);
- // distVSPoints.put(distance(ref, bottomRightCornerDelta), bottomRightCornerDelta);
- }
- return distVSPoints;
- }
-
- /**
- *
- * @param request
- * @return
- * a map with the couple distance and delta point to anchor by the middle of each side of the figure
- */
- protected Map<Double, PrecisionPoint> getMiddleDistances(final ChangeBoundsRequest request) {
- final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
- final Point moveDelta = request.getMoveDelta();
-
- PrecisionRectangle jointRect = getCompoundSourceRectangle();
- jointRect.translate(moveDelta);
- // calculate the delta to anchor on the middle top point
- final PrecisionPoint middleTopDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleTop = getSourceRectangle();
- baseRectMiddleTop.setPreciseLocation(baseRectMiddleTop.preciseX() + (baseRectMiddleTop.preciseWidth() / 2), baseRectMiddleTop.preciseY());
- baseRectMiddleTop.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleTop, jointRect }, middleTopDelta);
-
- // calculate the delta to anchor on the middle left point
- final PrecisionPoint middleLeftDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleLeft = getSourceRectangle();
- baseRectMiddleLeft.setPreciseLocation(baseRectMiddleLeft.preciseX(), baseRectMiddleLeft.preciseY() + (baseRectMiddleLeft.preciseWidth() / 2));
- baseRectMiddleLeft.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleLeft, jointRect }, middleLeftDelta);
-
- // calculate the delta to anchor on the middle right point
- final PrecisionPoint middleRightDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleRight = getSourceRectangle();
- baseRectMiddleRight.setPreciseLocation(baseRectMiddleRight.preciseX() + baseRectMiddleRight.preciseWidth(), baseRectMiddleRight.preciseY() + (baseRectMiddleRight.preciseHeight() / 2));
- baseRectMiddleRight.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleRight, jointRect }, middleRightDelta);
-
- // calculate the delta to anchor on the middle bottom
- final PrecisionPoint middleBottomDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleBottom = getSourceRectangle();
- baseRectMiddleBottom.setPreciseLocation(baseRectMiddleBottom.preciseX() + (baseRectMiddleBottom.preciseWidth() / 2), baseRectMiddleBottom.preciseY() + baseRectMiddleBottom.preciseHeight());
- baseRectMiddleBottom.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleBottom, jointRect }, middleBottomDelta);
-
- final Point ref = baseRectMiddleTop.getTopLeft();
- distVSPoints.put(distance(ref, middleTopDelta), middleTopDelta);
- distVSPoints.put(distance(ref, middleLeftDelta), middleLeftDelta);
- distVSPoints.put(distance(ref, middleRightDelta), middleRightDelta);
- distVSPoints.put(distance(ref, middleBottomDelta), middleBottomDelta);
- }
-
- return distVSPoints;
- }
-
- /**
- *
- * @param request
- * @return
- * a map with the couple distance and delta point to anchor by the center of the figure
- */
- protected Map<Double, PrecisionPoint> getCenterDistances(final ChangeBoundsRequest request) {
- final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
- final Point moveDelta = request.getMoveDelta();
-
- PrecisionRectangle jointRect = getCompoundSourceRectangle();
- jointRect.translate(moveDelta);
- // calculate the delta to anchor on the middle top point
- final PrecisionPoint centerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectCenter = getSourceRectangle();
- baseRectCenter.setPreciseLocation(baseRectCenter.preciseX() + (baseRectCenter.preciseWidth() / 2), baseRectCenter.preciseY() + (baseRectCenter.preciseHeight() / 2));
- baseRectCenter.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectCenter, jointRect }, centerDelta);
-
- final Point ref = baseRectCenter.getTopLeft();
- distVSPoints.put(distance(ref, centerDelta), centerDelta);
- }
-
- return distVSPoints;
- }
-
- /**
- *
- * @return
- * the compoundSourceRectangle
- */
- private PrecisionRectangle getCompoundSourceRectangle() {
- return new PrecisionRectangle(this.compoundSourceRectangle);
- }
-
- /**
- *
- * @return
- * the source rectangle
- */
- private PrecisionRectangle getSourceRectangle() {
- return new PrecisionRectangle(this.figureToSnapBounds);
- }
-
- /**
- *
- * @param pt1
- * a first point
- * @param pt2
- * the second point
- * @return
- * the distance between the two points
- */
- protected final double distance(final Point pt1, final Point pt2) {
- double deltaX = pt1.preciseX() - pt2.preciseX();
- double deltaY = pt1.preciseY() - pt2.preciseY();
- return Math.hypot(deltaX, deltaY);
- }
-
- /**
- *
- * @return
- * the snap helper
- */
- protected final SnapToHelper getSnapToHelper() {
- return this.helper;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Vincent Lorenzo - CEA LIST
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.SnapToHelper;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.tools.DragEditPartsTracker;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
+
+/**
+ *
+ * this class allows to determine the best location for a node on the grid
+ *
+ * Adapted code from DragEditPartsTrackerEx
+ * TODO : PapyrusDragEditPartTracker should use me
+ */
+@SuppressWarnings("restriction")
+public class NodeSnapHelper {
+
+ /**
+ * if true, we snap on the four corner of the figures
+ */
+ protected final boolean snapOnCorners;
+
+ /**
+ * if true, we snap on the four middle side of the figures
+ */
+ protected final boolean snapOnMiddles;
+
+ /**
+ * if true, we snap on the center of the figure
+ */
+ protected final boolean snapOnCenter;
+
+ /**
+ * the snap helper to use
+ */
+ private SnapToHelper helper;
+
+ /**
+ * the bounds of the figure to snap
+ */
+ private Rectangle figureToSnapBounds;
+
+ /**
+ * the compoundSourceRectangle, see {@link DragEditPartsTracker} for further informations
+ */
+ private Rectangle compoundSourceRectangle;
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param helper
+ * the snap helper
+ * @param figureToSnapBounds
+ * the bounds of the figure to snap
+ *
+ */
+ public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds) {
+ this(helper, figureToSnapBounds, figureToSnapBounds);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param helper
+ * the snap helper
+ * @param figureToSnapBounds
+ * the bounds of the figure to snap
+ * @param compoundSourceRectangle
+ * see {@link DragEditPartsTracker} for further informations
+ */
+ public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds, final Rectangle compoundSourceRectangle) {
+ this(helper, figureToSnapBounds, compoundSourceRectangle, true, false, false);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param helper
+ * @param figureToSnapBounds
+ * @param snapOnCorners
+ * @param snapOnMiddles
+ * @param snapOnCenter
+ */
+ public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds, final boolean snapOnCorners, final boolean snapOnMiddles, final boolean snapOnCenter) {
+ this(helper, figureToSnapBounds, figureToSnapBounds, snapOnCorners, snapOnMiddles, snapOnCenter);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param helper
+ * @param figureToSnapBounds
+ * @param compoundSourceRectangle
+ * @param snapOnCorners
+ * @param snapOnMiddles
+ * @param snapOnCenter
+ */
+ public NodeSnapHelper(final SnapToHelper helper, final Rectangle figureToSnapBounds, final Rectangle compoundSourceRectangle, final boolean snapOnCorners, final boolean snapOnMiddles, final boolean snapOnCenter) {
+ this.helper = helper;
+ this.figureToSnapBounds = figureToSnapBounds;
+ this.compoundSourceRectangle = compoundSourceRectangle;
+ this.snapOnCorners = snapOnCorners;
+ this.snapOnMiddles = snapOnMiddles;
+ this.snapOnCenter = snapOnCenter;
+ }
+
+ /**
+ * This method can be overridden by clients to customize the snapping
+ * behavior.
+ *
+ * @param request
+ * the <code>ChangeBoundsRequest</code> from which the move delta
+ * can be extracted and updated
+ * We use <code>ChangeBoundsRequest</code> to be compatible with snap edit part tracker!
+ */
+ @SuppressWarnings({ "unchecked" })
+ public void snapPoint(ChangeBoundsRequest request) {
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+
+ // test to know if we are moving using keyboard
+ // TODO not useful here
+ // if(!getCurrentInput().isAnyButtonDown()) {
+ // calculateSnapPointFromArrowKey(request);
+ // return;
+ // }
+ int restrictedDirection = 0;
+ restrictedDirection = restrictedDirection | PositionConstants.EAST;
+ restrictedDirection = restrictedDirection | PositionConstants.WEST;
+ restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
+ restrictedDirection = restrictedDirection | PositionConstants.NORTH;
+ request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
+
+ final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
+ if (this.snapOnCorners) {
+ distVSPoint.putAll(getCornerDistances(request));
+ }
+
+ if (this.snapOnMiddles) {
+ distVSPoint.putAll(getMiddleDistances(request));
+ }
+
+ if (this.snapOnCenter) {
+ distVSPoint.putAll(getCenterDistances(request));
+ }
+
+ final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
+ if (distances.size() > 0) {
+ double min = distances.get(0);
+ for (int i = 1; i < distances.size() - 1; i++) {
+ min = Math.min(min, distances.get(i));
+ }
+ request.setMoveDelta(distVSPoint.get(min));
+ }
+ }
+ }
+
+ /**
+ *
+ * @param request
+ * a move request
+ * @return
+ * the restricted direction for the request
+ */
+ protected final int getRestrictedDirection(final ChangeBoundsRequest request) {
+ int restrictedDirection = 0;
+ final Point delta = request.getMoveDelta();
+ if (delta.x > 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.EAST;
+ restrictedDirection = restrictedDirection | PositionConstants.WEST;
+ }
+ if (delta.x < 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.EAST;
+ restrictedDirection = restrictedDirection | PositionConstants.WEST;
+ }
+ if (delta.y > 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
+ restrictedDirection = restrictedDirection | PositionConstants.NORTH;
+ }
+ if (delta.y < 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
+ restrictedDirection = restrictedDirection | PositionConstants.NORTH;
+ }
+ return restrictedDirection;
+ }
+
+ /**
+ *
+ * @param request
+ * the move request
+ */
+ @SuppressWarnings("unchecked")
+ protected void calculateSnapPointFromArrowKey(final ChangeBoundsRequest request) {
+ if (request.getEditParts().size() == 0) {
+ return;
+ }
+ final Object ep = request.getEditParts().get(0);
+ if (!(ep instanceof IGraphicalEditPart)) {
+ return;
+ }
+ final RootEditPart root = ((IGraphicalEditPart) ep).getRoot();
+ if (!(root instanceof DiagramRootEditPart)) {
+ return;
+ }
+ final double gridSpacing = ((DiagramRootEditPart) root).getGridSpacing();
+ int max = (int) (1 + gridSpacing);
+ int restrictedDirection = getRestrictedDirection(request);
+ final Point delta = request.getMoveDelta();
+ final Point newDelta = new Point(0, 0);
+ int newMove = 0;
+ while (newMove < max) {
+ newMove++;
+ if (delta.x > 0) {
+ newDelta.x = newMove + delta.x;
+ }
+ if (delta.x < 0) {
+ newDelta.x = (-newMove) + delta.x;
+ }
+ if (delta.y > 0) {
+ newDelta.y = newMove + delta.y;
+ }
+ if (delta.y < 0) {
+ newDelta.y = (-newMove) + delta.y;
+ }
+ request.setMoveDelta(newDelta);
+ request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
+
+ final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
+ if (this.snapOnCorners) {
+ distVSPoint.putAll(getCornerDistances(request));
+ }
+
+ if (this.snapOnMiddles) {
+ distVSPoint.putAll(getMiddleDistances(request));
+ }
+
+ if (this.snapOnCenter) {
+ distVSPoint.putAll(getCenterDistances(request));
+ }
+
+ final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
+ if (distances.size() > 0) {
+ double min = distances.get(0);
+ // We look for the minus distance
+ for (int i = 1; i < distances.size() - 1; i++) {
+ min = Math.min(min, distances.get(i));
+ }
+ final Point minPoint = distVSPoint.get(min);
+ // the distance can't be null
+ if (minPoint.x != 0 || minPoint.y != 0) {
+ // the calculate move must be in the same direction than the keyboard move
+ if (Integer.signum(minPoint.x) == Integer.signum(delta.x) && Integer.signum(minPoint.y) == Integer.signum(delta.y)) {
+ request.setMoveDelta(distVSPoint.get(min));
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ * a map with the couple distance and delta point to anchor by the corner of the figure
+ */
+ protected Map<Double, PrecisionPoint> getCornerDistances(final ChangeBoundsRequest request) {
+ final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+ final Point moveDelta = request.getMoveDelta();
+ PrecisionRectangle jointRect = getCompoundSourceRectangle();
+ jointRect.translate(moveDelta);
+
+ // calculate the delta to anchor on the top left corner
+ final PrecisionPoint topLeftCornerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectTopLeft = getSourceRectangle();
+ baseRectTopLeft.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectTopLeft, jointRect }, topLeftCornerDelta);
+
+ // calculate the delta to anchor on the top right corner
+ final PrecisionPoint topRightCornerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectTopRight = getSourceRectangle();
+ baseRectTopRight.setX(baseRectTopRight.x + baseRectTopRight.width);
+ baseRectTopRight.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectTopRight, jointRect }, topRightCornerDelta);
+
+ // calculate the delta to anchor on the bottom left corner
+ final PrecisionPoint bottomLeftCornerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectBottomLeft = getSourceRectangle();
+ baseRectBottomLeft.setY(baseRectBottomLeft.y + baseRectBottomLeft.height);
+ baseRectBottomLeft.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectBottomLeft, jointRect }, bottomLeftCornerDelta);
+
+ // calculate the delta to anchor on the bottom right corner
+ final PrecisionPoint bottomRightCornerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectBottomRight = getSourceRectangle();
+ baseRectBottomRight.setX(baseRectBottomRight.x + baseRectBottomRight.width);
+ baseRectBottomRight.setY(baseRectBottomRight.y + baseRectBottomRight.height);
+ baseRectBottomRight.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectBottomRight, jointRect }, bottomRightCornerDelta);
+
+ final Point ref = baseRectTopLeft.getTopLeft();
+ distVSPoints.put(distance(ref, topLeftCornerDelta), topLeftCornerDelta);
+ // distVSPoints.put(distance(ref, topRightCornerDelta), topRightCornerDelta);
+ // distVSPoints.put(distance(ref, bottomLeftCornerDelta), bottomLeftCornerDelta);
+ // distVSPoints.put(distance(ref, bottomRightCornerDelta), bottomRightCornerDelta);
+ }
+ return distVSPoints;
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ * a map with the couple distance and delta point to anchor by the middle of each side of the figure
+ */
+ protected Map<Double, PrecisionPoint> getMiddleDistances(final ChangeBoundsRequest request) {
+ final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+ final Point moveDelta = request.getMoveDelta();
+
+ PrecisionRectangle jointRect = getCompoundSourceRectangle();
+ jointRect.translate(moveDelta);
+ // calculate the delta to anchor on the middle top point
+ final PrecisionPoint middleTopDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleTop = getSourceRectangle();
+ baseRectMiddleTop.setPreciseLocation(baseRectMiddleTop.preciseX() + (baseRectMiddleTop.preciseWidth() / 2), baseRectMiddleTop.preciseY());
+ baseRectMiddleTop.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleTop, jointRect }, middleTopDelta);
+
+ // calculate the delta to anchor on the middle left point
+ final PrecisionPoint middleLeftDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleLeft = getSourceRectangle();
+ baseRectMiddleLeft.setPreciseLocation(baseRectMiddleLeft.preciseX(), baseRectMiddleLeft.preciseY() + (baseRectMiddleLeft.preciseWidth() / 2));
+ baseRectMiddleLeft.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleLeft, jointRect }, middleLeftDelta);
+
+ // calculate the delta to anchor on the middle right point
+ final PrecisionPoint middleRightDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleRight = getSourceRectangle();
+ baseRectMiddleRight.setPreciseLocation(baseRectMiddleRight.preciseX() + baseRectMiddleRight.preciseWidth(), baseRectMiddleRight.preciseY() + (baseRectMiddleRight.preciseHeight() / 2));
+ baseRectMiddleRight.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleRight, jointRect }, middleRightDelta);
+
+ // calculate the delta to anchor on the middle bottom
+ final PrecisionPoint middleBottomDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleBottom = getSourceRectangle();
+ baseRectMiddleBottom.setPreciseLocation(baseRectMiddleBottom.preciseX() + (baseRectMiddleBottom.preciseWidth() / 2), baseRectMiddleBottom.preciseY() + baseRectMiddleBottom.preciseHeight());
+ baseRectMiddleBottom.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleBottom, jointRect }, middleBottomDelta);
+
+ final Point ref = baseRectMiddleTop.getTopLeft();
+ distVSPoints.put(distance(ref, middleTopDelta), middleTopDelta);
+ distVSPoints.put(distance(ref, middleLeftDelta), middleLeftDelta);
+ distVSPoints.put(distance(ref, middleRightDelta), middleRightDelta);
+ distVSPoints.put(distance(ref, middleBottomDelta), middleBottomDelta);
+ }
+
+ return distVSPoints;
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ * a map with the couple distance and delta point to anchor by the center of the figure
+ */
+ protected Map<Double, PrecisionPoint> getCenterDistances(final ChangeBoundsRequest request) {
+ final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+ final Point moveDelta = request.getMoveDelta();
+
+ PrecisionRectangle jointRect = getCompoundSourceRectangle();
+ jointRect.translate(moveDelta);
+ // calculate the delta to anchor on the middle top point
+ final PrecisionPoint centerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectCenter = getSourceRectangle();
+ baseRectCenter.setPreciseLocation(baseRectCenter.preciseX() + (baseRectCenter.preciseWidth() / 2), baseRectCenter.preciseY() + (baseRectCenter.preciseHeight() / 2));
+ baseRectCenter.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectCenter, jointRect }, centerDelta);
+
+ final Point ref = baseRectCenter.getTopLeft();
+ distVSPoints.put(distance(ref, centerDelta), centerDelta);
+ }
+
+ return distVSPoints;
+ }
+
+ /**
+ *
+ * @return
+ * the compoundSourceRectangle
+ */
+ private PrecisionRectangle getCompoundSourceRectangle() {
+ return new PrecisionRectangle(this.compoundSourceRectangle);
+ }
+
+ /**
+ *
+ * @return
+ * the source rectangle
+ */
+ private PrecisionRectangle getSourceRectangle() {
+ return new PrecisionRectangle(this.figureToSnapBounds);
+ }
+
+ /**
+ *
+ * @param pt1
+ * a first point
+ * @param pt2
+ * the second point
+ * @return
+ * the distance between the two points
+ */
+ protected final double distance(final Point pt1, final Point pt2) {
+ double deltaX = pt1.preciseX() - pt2.preciseX();
+ double deltaY = pt1.preciseY() - pt2.preciseY();
+ return Math.hypot(deltaX, deltaY);
+ }
+
+ /**
+ *
+ * @return
+ * the snap helper
+ */
+ protected final SnapToHelper getSnapToHelper() {
+ return this.helper;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointHandle.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointHandle.java
index f032617b50b..d6e485abca1 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointHandle.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointHandle.java
@@ -1,87 +1,87 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.snap;
-
-import org.eclipse.draw2d.ConnectionLocator;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.DragTracker;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.handles.ConnectionEndpointHandle;
-
-
-/**
- *
- * This class allows us to provide our own
- *
- */
-public class PapyrusConnectionEndpointHandle extends ConnectionEndpointHandle {
-
- /**
- * Creates a new ConnectionStartHandle, sets its owner to <code>owner</code> , and sets its locator to a {@link ConnectionLocator}.
- *
- * @param owner
- * the ConnectionEditPart owner
- * @param endPoint
- * one of {@link ConnectionLocator#SOURCE} or {@link ConnectionLocator#TARGET}.
- */
- public PapyrusConnectionEndpointHandle(ConnectionEditPart owner, int endPoint) {
- super(owner, endPoint);
- }
-
- /**
- * Creates a new ConnectionStartHandle and sets its owner to <code>owner</code>. If the handle is fixed, it cannot be dragged.
- *
- * @param owner
- * the ConnectionEditPart owner
- * @param fixed
- * if true, handle cannot be dragged.
- * @param endPoint
- * one of {@link ConnectionLocator#SOURCE} or {@link ConnectionLocator#TARGET}.
- */
- public PapyrusConnectionEndpointHandle(ConnectionEditPart owner, boolean fixed, int endPoint) {
- super(owner, fixed, endPoint);
- }
-
- /**
- * Creates a new ConnectionStartHandle.
- *
- * @param endPoint
- * one of {@link ConnectionLocator#SOURCE} or {@link ConnectionLocator#TARGET}.
- */
- public PapyrusConnectionEndpointHandle(int endPoint) {
- super(endPoint);
- }
-
- /**
- * Creates and returns a new {@link PapyrusConnectionEndpointTracker}.
- *
- * @return the new ConnectionEndpointTracker
- */
- @Override
- protected DragTracker createDragTracker() {
- if (isFixed()) {
- return null;
- }
- PapyrusConnectionEndpointTracker tracker = new PapyrusConnectionEndpointTracker((ConnectionEditPart) getOwner());
- if (getEndPoint() == ConnectionLocator.SOURCE) {
- tracker.setCommandName(RequestConstants.REQ_RECONNECT_SOURCE);
- } else {
- tracker.setCommandName(RequestConstants.REQ_RECONNECT_TARGET);
- }
- tracker.setDefaultCursor(getCursor());
- return tracker;
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.draw2d.ConnectionLocator;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.handles.ConnectionEndpointHandle;
+
+
+/**
+ *
+ * This class allows us to provide our own
+ *
+ */
+public class PapyrusConnectionEndpointHandle extends ConnectionEndpointHandle {
+
+ /**
+ * Creates a new ConnectionStartHandle, sets its owner to <code>owner</code> , and sets its locator to a {@link ConnectionLocator}.
+ *
+ * @param owner
+ * the ConnectionEditPart owner
+ * @param endPoint
+ * one of {@link ConnectionLocator#SOURCE} or {@link ConnectionLocator#TARGET}.
+ */
+ public PapyrusConnectionEndpointHandle(ConnectionEditPart owner, int endPoint) {
+ super(owner, endPoint);
+ }
+
+ /**
+ * Creates a new ConnectionStartHandle and sets its owner to <code>owner</code>. If the handle is fixed, it cannot be dragged.
+ *
+ * @param owner
+ * the ConnectionEditPart owner
+ * @param fixed
+ * if true, handle cannot be dragged.
+ * @param endPoint
+ * one of {@link ConnectionLocator#SOURCE} or {@link ConnectionLocator#TARGET}.
+ */
+ public PapyrusConnectionEndpointHandle(ConnectionEditPart owner, boolean fixed, int endPoint) {
+ super(owner, fixed, endPoint);
+ }
+
+ /**
+ * Creates a new ConnectionStartHandle.
+ *
+ * @param endPoint
+ * one of {@link ConnectionLocator#SOURCE} or {@link ConnectionLocator#TARGET}.
+ */
+ public PapyrusConnectionEndpointHandle(int endPoint) {
+ super(endPoint);
+ }
+
+ /**
+ * Creates and returns a new {@link PapyrusConnectionEndpointTracker}.
+ *
+ * @return the new ConnectionEndpointTracker
+ */
+ @Override
+ protected DragTracker createDragTracker() {
+ if (isFixed()) {
+ return null;
+ }
+ PapyrusConnectionEndpointTracker tracker = new PapyrusConnectionEndpointTracker((ConnectionEditPart) getOwner());
+ if (getEndPoint() == ConnectionLocator.SOURCE) {
+ tracker.setCommandName(RequestConstants.REQ_RECONNECT_SOURCE);
+ } else {
+ tracker.setCommandName(RequestConstants.REQ_RECONNECT_TARGET);
+ }
+ tracker.setDefaultCursor(getCursor());
+ return tracker;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointTracker.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointTracker.java
index 5ddd4c657ed..2150e27be3b 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointTracker.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusConnectionEndpointTracker.java
@@ -1,110 +1,110 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap;
-
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.ConnectionEditPart;
-import org.eclipse.gef.DragTracker;
-import org.eclipse.gef.SnapToHelper;
-import org.eclipse.gef.requests.ReconnectRequest;
-import org.eclipse.papyrus.infra.gmfdiag.common.snap.copy.ConnectionEndpointTracker;
-
-/**
- * A DragTracker that moves the endpoint of a connection to a grid point
- */
-public class PapyrusConnectionEndpointTracker extends ConnectionEndpointTracker implements DragTracker {
-
- /**
- * Constructs a new ConnectionEndpointTracker for the given
- * ConnectionEditPart.
- *
- * @param cep
- * the ConnectionEditPart
- */
- public PapyrusConnectionEndpointTracker(ConnectionEditPart cep) {
- super(cep);
- }
-
-
- /**
- * Updates the request location.
- *
- * @see org.eclipse.gef.tools.TargetingTool#updateTargetRequest()
- */
- @Override
- protected void updateTargetRequest() {
- // adapted code from ConnectionBendpointTrackerEx
- ReconnectRequest request = (ReconnectRequest) getTargetRequest();
- // Request request = getTargetRequest();
-
- Point originalLocation = null;
- if (originalLocation == null) {
- originalLocation = getStartLocation().getCopy();
- }
-
- Dimension delta = getDragMoveDelta();
-
- if (getCurrentInput().isShiftKeyDown()) {
- float ratio = 0;
- if (delta.width != 0) {
- ratio = (float) delta.height / (float) delta.width;
- }
-
- ratio = Math.abs(ratio);
- if (ratio > 0.5 && ratio < 1.5) {
- if (Math.abs(delta.height) > Math.abs(delta.width)) {
- if (delta.height > 0) {
- delta.height = Math.abs(delta.width);
- } else {
- delta.height = -Math.abs(delta.width);
- }
- } else {
- if (delta.width > 0) {
- delta.width = Math.abs(delta.height);
- } else {
- delta.width = -Math.abs(delta.height);
- }
- }
- } else {
- if (Math.abs(delta.width) > Math.abs(delta.height)) {
- delta.height = 0;
- } else {
- delta.width = 0;
- }
- }
- }
- Point moveDelta = new Point(delta.width, delta.height);
- SnapToHelper snapToHelper = (SnapToHelper) getConnectionEditPart().getAdapter(SnapToHelper.class);
-
- Rectangle rect = new Rectangle(originalLocation.x, originalLocation.y, 1, 1);
- PrecisionRectangle sourceRectangle = null;
- if (sourceRectangle == null) {
- sourceRectangle = new PrecisionRectangle(rect);
- }
-
- if (snapToHelper != null && !getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING)) {
- PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
- baseRect.translate(moveDelta);
- PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
- snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRect }, preciseDelta);
- Point newLocation = originalLocation.getCopy().translate(preciseDelta);
- request.setLocation(newLocation);
- } else {
- request.setLocation(getLocation());
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.ConnectionEditPart;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.SnapToHelper;
+import org.eclipse.gef.requests.ReconnectRequest;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.copy.ConnectionEndpointTracker;
+
+/**
+ * A DragTracker that moves the endpoint of a connection to a grid point
+ */
+public class PapyrusConnectionEndpointTracker extends ConnectionEndpointTracker implements DragTracker {
+
+ /**
+ * Constructs a new ConnectionEndpointTracker for the given
+ * ConnectionEditPart.
+ *
+ * @param cep
+ * the ConnectionEditPart
+ */
+ public PapyrusConnectionEndpointTracker(ConnectionEditPart cep) {
+ super(cep);
+ }
+
+
+ /**
+ * Updates the request location.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#updateTargetRequest()
+ */
+ @Override
+ protected void updateTargetRequest() {
+ // adapted code from ConnectionBendpointTrackerEx
+ ReconnectRequest request = (ReconnectRequest) getTargetRequest();
+ // Request request = getTargetRequest();
+
+ Point originalLocation = null;
+ if (originalLocation == null) {
+ originalLocation = getStartLocation().getCopy();
+ }
+
+ Dimension delta = getDragMoveDelta();
+
+ if (getCurrentInput().isShiftKeyDown()) {
+ float ratio = 0;
+ if (delta.width != 0) {
+ ratio = (float) delta.height / (float) delta.width;
+ }
+
+ ratio = Math.abs(ratio);
+ if (ratio > 0.5 && ratio < 1.5) {
+ if (Math.abs(delta.height) > Math.abs(delta.width)) {
+ if (delta.height > 0) {
+ delta.height = Math.abs(delta.width);
+ } else {
+ delta.height = -Math.abs(delta.width);
+ }
+ } else {
+ if (delta.width > 0) {
+ delta.width = Math.abs(delta.height);
+ } else {
+ delta.width = -Math.abs(delta.height);
+ }
+ }
+ } else {
+ if (Math.abs(delta.width) > Math.abs(delta.height)) {
+ delta.height = 0;
+ } else {
+ delta.width = 0;
+ }
+ }
+ }
+ Point moveDelta = new Point(delta.width, delta.height);
+ SnapToHelper snapToHelper = (SnapToHelper) getConnectionEditPart().getAdapter(SnapToHelper.class);
+
+ Rectangle rect = new Rectangle(originalLocation.x, originalLocation.y, 1, 1);
+ PrecisionRectangle sourceRectangle = null;
+ if (sourceRectangle == null) {
+ sourceRectangle = new PrecisionRectangle(rect);
+ }
+
+ if (snapToHelper != null && !getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING)) {
+ PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
+ baseRect.translate(moveDelta);
+ PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
+ snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRect }, preciseDelta);
+ Point newLocation = originalLocation.getCopy().translate(preciseDelta);
+ request.setLocation(newLocation);
+ } else {
+ request.setLocation(getLocation());
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragBorderNodeEditPartTrackerEx.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragBorderNodeEditPartTrackerEx.java
index 0ccea8a17bd..1990c571f0e 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragBorderNodeEditPartTrackerEx.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragBorderNodeEditPartTrackerEx.java
@@ -1,59 +1,59 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.snap;
-
-import org.eclipse.gef.EditPart;
-
-/**
- *
- * @author Vincent Lorenzo
- *
- */
-public class PapyrusDragBorderNodeEditPartTrackerEx extends PapyrusDragEditPartsTrackerEx {
-
- /**
- *
- * Constructor.
- *
- * @param sourceEditPart
- */
- public PapyrusDragBorderNodeEditPartTrackerEx(EditPart sourceEditPart) {
- this(sourceEditPart, false, false, true);
- }
-
- /**
- *
- * Constructor.
- *
- * @param sourceEditPart
- * @param snapOnCorners
- * @param snapOnMiddles
- * @param snapOnCenter
- */
- public PapyrusDragBorderNodeEditPartTrackerEx(EditPart sourceEditPart, boolean snapOnCorners, boolean snapOnMiddles, boolean snapOnCenter) {
- super(sourceEditPart, snapOnCorners, snapOnMiddles, snapOnCenter);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.gmfdiag.common.snap.copy.CustomDragEditPartsTracker#isMove()
- *
- * @return
- */
- @Override
- protected boolean isMove() {
- return true;// see org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart.getEditPartTracker
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.gef.EditPart;
+
+/**
+ *
+ * @author Vincent Lorenzo
+ *
+ */
+public class PapyrusDragBorderNodeEditPartTrackerEx extends PapyrusDragEditPartsTrackerEx {
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param sourceEditPart
+ */
+ public PapyrusDragBorderNodeEditPartTrackerEx(EditPart sourceEditPart) {
+ this(sourceEditPart, false, false, true);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param sourceEditPart
+ * @param snapOnCorners
+ * @param snapOnMiddles
+ * @param snapOnCenter
+ */
+ public PapyrusDragBorderNodeEditPartTrackerEx(EditPart sourceEditPart, boolean snapOnCorners, boolean snapOnMiddles, boolean snapOnCenter) {
+ super(sourceEditPart, snapOnCorners, snapOnMiddles, snapOnCenter);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.snap.copy.CustomDragEditPartsTracker#isMove()
+ *
+ * @return
+ */
+ @Override
+ protected boolean isMove() {
+ return true;// see org.eclipse.gmf.runtime.diagram.ui.editparts.AbstractBorderItemEditPart.getEditPartTracker
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragEditPartsTrackerEx.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragEditPartsTrackerEx.java
index d32bd19fb27..7ede7bea01c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragEditPartsTrackerEx.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/PapyrusDragEditPartsTrackerEx.java
@@ -1,377 +1,377 @@
-/******************************************************************************
- * Copyright (c) 2002, 2008 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.papyrus.infra.gmfdiag.common.snap;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.RootEditPart;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
-import org.eclipse.papyrus.infra.gmfdiag.common.snap.copy.DragEditPartsTrackerEx;
-
-/**
- * A dervied DragEditPartsTRacker that sends REQ_DRAG instead of REQ_ORPHAN
- * and REQ_DROP instead of REQ_ADD
- *
- * @author melaasar
- */
-// TODO see Bug 424007. CustomDragEditPartsTracker and others classes in package snap.copy will be destroyed when the gef bug 424007 will be resolved.
-@SuppressWarnings("restriction")
-public class PapyrusDragEditPartsTrackerEx extends DragEditPartsTrackerEx {
-
- /**
- * if true, we snap on the four corner of the figures
- */
- protected final boolean snapOnCorners;
-
- /**
- * if true, we snap on the four middle side of the figures
- */
- protected final boolean snapOnMiddles;
-
- /**
- * if true, we snap on the center of the figure
- */
- protected final boolean snapOnCenter;
-
-
- /**
- * @param sourceEditPart
- */
- public PapyrusDragEditPartsTrackerEx(final EditPart sourceEditPart) {
- this(sourceEditPart, true, false, false);
- }
-
- /**
- *
- * Constructor.
- *
- * @param sourceEditPart
- * @param snapOnCorners
- * @param snapOnMiddles
- * @param snapOnCenter
- */
- public PapyrusDragEditPartsTrackerEx(final EditPart sourceEditPart, final boolean snapOnCorners, final boolean snapOnMiddles, final boolean snapOnCenter) {
- super(sourceEditPart);
- this.snapOnCorners = snapOnCorners;
- this.snapOnMiddles = snapOnMiddles;
- this.snapOnCenter = snapOnCenter;
- }
-
- /**
- * This method can be overridden by clients to customize the snapping
- * behavior.
- *
- * @param request
- * the <code>ChangeBoundsRequest</code> from which the move delta
- * can be extracted and updated
- * @since 3.4
- */
- @Override
- @SuppressWarnings({ "unchecked" })
- protected void snapPoint(ChangeBoundsRequest request) {
- if (getSnapToHelper() != null && request.isSnapToEnabled() && request.getEditParts().size() > 0) {
-
- // test to know if we are moving using keyboard
- if (!getCurrentInput().isAnyButtonDown()) {
- calculateSnapPointFromArrowKey(request);
- return;
- }
- int restrictedDirection = 0;
- restrictedDirection = restrictedDirection | PositionConstants.EAST;
- restrictedDirection = restrictedDirection | PositionConstants.WEST;
- restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
- restrictedDirection = restrictedDirection | PositionConstants.NORTH;
- request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
-
- final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
- if (this.snapOnCorners) {
- distVSPoint.putAll(getCornerDistances(request));
- }
-
- if (this.snapOnMiddles) {
- distVSPoint.putAll(getMiddleDistances(request));
- }
-
- if (this.snapOnCenter) {
- distVSPoint.putAll(getCenterDistances(request));
- }
-
- final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
- if (distances.size() > 0) {
- double min = distances.get(0);
- for (int i = 1; i < distances.size() - 1; i++) {
- min = Math.min(min, distances.get(i));
- }
- request.setMoveDelta(distVSPoint.get(min));
- }
- }
- }
-
- /**
- *
- * @param request
- * a move request
- * @return
- * the restricted direction for the request
- */
- protected final int getRestrictedDirection(final ChangeBoundsRequest request) {
- int restrictedDirection = 0;
- final Point delta = request.getMoveDelta();
- if (delta.x > 0) {
- restrictedDirection = restrictedDirection | PositionConstants.EAST;
- restrictedDirection = restrictedDirection | PositionConstants.WEST;
- }
- if (delta.x < 0) {
- restrictedDirection = restrictedDirection | PositionConstants.EAST;
- restrictedDirection = restrictedDirection | PositionConstants.WEST;
- }
- if (delta.y > 0) {
- restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
- restrictedDirection = restrictedDirection | PositionConstants.NORTH;
- }
- if (delta.y < 0) {
- restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
- restrictedDirection = restrictedDirection | PositionConstants.NORTH;
- }
- return restrictedDirection;
- }
-
- /**
- *
- * @param request
- * the move request
- */
- @SuppressWarnings("unchecked")
- protected void calculateSnapPointFromArrowKey(final ChangeBoundsRequest request) {
- if (request.getEditParts().size() == 0) {
- return;
- }
- final Object ep = request.getEditParts().get(0);
- if (!(ep instanceof IGraphicalEditPart)) {
- return;
- }
- final RootEditPart root = ((IGraphicalEditPart) ep).getRoot();
- if (!(root instanceof DiagramRootEditPart)) {
- return;
- }
- final double gridSpacing = ((DiagramRootEditPart) root).getGridSpacing();
- int max = (int) (1 + gridSpacing);
- int restrictedDirection = getRestrictedDirection(request);
- final Point delta = request.getMoveDelta();
- final Point newDelta = new Point(0, 0);
- int newMove = 0;
- while (newMove < max) {
- newMove++;
- if (delta.x > 0) {
- newDelta.x = newMove + delta.x;
- }
- if (delta.x < 0) {
- newDelta.x = (-newMove) + delta.x;
- }
- if (delta.y > 0) {
- newDelta.y = newMove + delta.y;
- }
- if (delta.y < 0) {
- newDelta.y = (-newMove) + delta.y;
- }
- request.setMoveDelta(newDelta);
- request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
-
- final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
- if (this.snapOnCorners) {
- distVSPoint.putAll(getCornerDistances(request));
- }
-
- if (this.snapOnMiddles) {
- distVSPoint.putAll(getMiddleDistances(request));
- }
-
- if (this.snapOnCenter) {
- distVSPoint.putAll(getCenterDistances(request));
- }
-
- final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
- if (distances.size() > 0) {
- double min = distances.get(0);
- // We look for the minus distance
- for (int i = 1; i < distances.size() - 1; i++) {
- min = Math.min(min, distances.get(i));
- }
- final Point minPoint = distVSPoint.get(min);
- // the distance can't be null
- if (minPoint.x != 0 || minPoint.y != 0) {
- // the calculate move must be in the same direction than the keyboard move
- if (Integer.signum(minPoint.x) == Integer.signum(delta.x) && Integer.signum(minPoint.y) == Integer.signum(delta.y)) {
- request.setMoveDelta(distVSPoint.get(min));
- return;
- }
- }
- }
- }
- }
-
- /**
- *
- * @param request
- * @return
- * a map with the couple distance and delta point to anchor by the corner of the figure
- */
- protected Map<Double, PrecisionPoint> getCornerDistances(final ChangeBoundsRequest request) {
- final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
- final Point moveDelta = request.getMoveDelta();
- PrecisionRectangle jointRect = getCompoundSourceRectangle();
- jointRect.translate(moveDelta);
-
- // calculate the delta to anchor on the top left corner
- final PrecisionPoint topLeftCornerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectTopLeft = getSourceRectangle();
- baseRectTopLeft.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectTopLeft, jointRect }, topLeftCornerDelta);
-
- // FIXME : add preferences and re-activate this part of the code
-
- // //calculate the delta to anchor on the top right corner
- // final PrecisionPoint topRightCornerDelta = new PrecisionPoint(moveDelta);
- // final PrecisionRectangle baseRectTopRight = getSourceRectangle();
- // baseRectTopRight.setX(baseRectTopRight.x + baseRectTopRight.width);
- // baseRectTopRight.translate(moveDelta);
- // getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[]{ baseRectTopRight, jointRect }, topRightCornerDelta);
- //
- // //calculate the delta to anchor on the bottom left corner
- // final PrecisionPoint bottomLeftCornerDelta = new PrecisionPoint(moveDelta);
- // final PrecisionRectangle baseRectBottomLeft = getSourceRectangle();
- // baseRectBottomLeft.setY(baseRectBottomLeft.y + baseRectBottomLeft.height);
- // baseRectBottomLeft.translate(moveDelta);
- // getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[]{ baseRectBottomLeft, jointRect }, bottomLeftCornerDelta);
- //
- // //calculate the delta to anchor on the bottom right corner
- // final PrecisionPoint bottomRightCornerDelta = new PrecisionPoint(moveDelta);
- // final PrecisionRectangle baseRectBottomRight = getSourceRectangle();
- // baseRectBottomRight.setX(baseRectBottomRight.x + baseRectBottomRight.width);
- // baseRectBottomRight.setY(baseRectBottomRight.y + baseRectBottomRight.height);
- // baseRectBottomRight.translate(moveDelta);
- // getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[]{ baseRectBottomRight, jointRect }, bottomRightCornerDelta);
-
- final Point ref = baseRectTopLeft.getTopLeft();
- distVSPoints.put(distance(ref, topLeftCornerDelta), topLeftCornerDelta);
- // distVSPoints.put(distance(ref, topRightCornerDelta), topRightCornerDelta);
- // distVSPoints.put(distance(ref, bottomLeftCornerDelta), bottomLeftCornerDelta);
- // distVSPoints.put(distance(ref, bottomRightCornerDelta), bottomRightCornerDelta);
- }
- return distVSPoints;
- }
-
- /**
- *
- * @param request
- * @return
- * a map with the couple distance and delta point to anchor by the middle of each side of the figure
- */
- protected Map<Double, PrecisionPoint> getMiddleDistances(final ChangeBoundsRequest request) {
- final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
- final Point moveDelta = request.getMoveDelta();
-
- PrecisionRectangle jointRect = getCompoundSourceRectangle();
- jointRect.translate(moveDelta);
- // calculate the delta to anchor on the middle top point
- final PrecisionPoint middleTopDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleTop = getSourceRectangle();
- baseRectMiddleTop.setPreciseLocation(baseRectMiddleTop.preciseX() + (baseRectMiddleTop.preciseWidth() / 2), baseRectMiddleTop.preciseY());
- baseRectMiddleTop.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleTop, jointRect }, middleTopDelta);
-
- // calculate the delta to anchor on the middle left point
- final PrecisionPoint middleLeftDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleLeft = getSourceRectangle();
- baseRectMiddleLeft.setPreciseLocation(baseRectMiddleLeft.preciseX(), baseRectMiddleLeft.preciseY() + (baseRectMiddleLeft.preciseWidth() / 2));
- baseRectMiddleLeft.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleLeft, jointRect }, middleLeftDelta);
-
- // calculate the delta to anchor on the middle right point
- final PrecisionPoint middleRightDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleRight = getSourceRectangle();
- baseRectMiddleRight.setPreciseLocation(baseRectMiddleRight.preciseX() + baseRectMiddleRight.preciseWidth(), baseRectMiddleRight.preciseY() + (baseRectMiddleRight.preciseHeight() / 2));
- baseRectMiddleRight.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleRight, jointRect }, middleRightDelta);
-
- // calculate the delta to anchor on the middle bottom
- final PrecisionPoint middleBottomDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectMiddleBottom = getSourceRectangle();
- baseRectMiddleBottom.setPreciseLocation(baseRectMiddleBottom.preciseX() + (baseRectMiddleBottom.preciseWidth() / 2), baseRectMiddleBottom.preciseY() + baseRectMiddleBottom.preciseHeight());
- baseRectMiddleBottom.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleBottom, jointRect }, middleBottomDelta);
-
- final Point ref = baseRectMiddleTop.getTopLeft();
- distVSPoints.put(distance(ref, middleTopDelta), middleTopDelta);
- distVSPoints.put(distance(ref, middleLeftDelta), middleLeftDelta);
- distVSPoints.put(distance(ref, middleRightDelta), middleRightDelta);
- distVSPoints.put(distance(ref, middleBottomDelta), middleBottomDelta);
- }
-
- return distVSPoints;
- }
-
- /**
- *
- * @param request
- * @return
- * a map with the couple distance and delta point to anchor by the center of the figure
- */
- protected Map<Double, PrecisionPoint> getCenterDistances(final ChangeBoundsRequest request) {
- final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
- if (getSnapToHelper() != null && request.isSnapToEnabled()) {
- final Point moveDelta = request.getMoveDelta();
-
- PrecisionRectangle jointRect = getCompoundSourceRectangle();
- jointRect.translate(moveDelta);
- // calculate the delta to anchor on the middle top point
- final PrecisionPoint centerDelta = new PrecisionPoint(moveDelta);
- final PrecisionRectangle baseRectCenter = getSourceRectangle();
- baseRectCenter.setPreciseLocation(baseRectCenter.preciseX() + (baseRectCenter.preciseWidth() / 2), baseRectCenter.preciseY() + (baseRectCenter.preciseHeight() / 2));
- baseRectCenter.translate(moveDelta);
- getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectCenter, jointRect }, centerDelta);
-
- final Point ref = baseRectCenter.getTopLeft();
- distVSPoints.put(distance(ref, centerDelta), centerDelta);
- }
-
- return distVSPoints;
- }
-
- /**
- *
- * @param pt1
- * a first point
- * @param pt2
- * the second point
- * @return
- * the distance between the two points
- */
- protected final double distance(final Point pt1, final Point pt2) {
- double deltaX = pt1.preciseX() - pt2.preciseX();
- double deltaY = pt1.preciseY() - pt2.preciseY();
- return Math.hypot(deltaX, deltaY);
- }
-}
+/******************************************************************************
+ * Copyright (c) 2002, 2008 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.papyrus.infra.gmfdiag.common.snap;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.RootEditPart;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramRootEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
+import org.eclipse.papyrus.infra.gmfdiag.common.snap.copy.DragEditPartsTrackerEx;
+
+/**
+ * A dervied DragEditPartsTRacker that sends REQ_DRAG instead of REQ_ORPHAN
+ * and REQ_DROP instead of REQ_ADD
+ *
+ * @author melaasar
+ */
+// TODO see Bug 424007. CustomDragEditPartsTracker and others classes in package snap.copy will be destroyed when the gef bug 424007 will be resolved.
+@SuppressWarnings("restriction")
+public class PapyrusDragEditPartsTrackerEx extends DragEditPartsTrackerEx {
+
+ /**
+ * if true, we snap on the four corner of the figures
+ */
+ protected final boolean snapOnCorners;
+
+ /**
+ * if true, we snap on the four middle side of the figures
+ */
+ protected final boolean snapOnMiddles;
+
+ /**
+ * if true, we snap on the center of the figure
+ */
+ protected final boolean snapOnCenter;
+
+
+ /**
+ * @param sourceEditPart
+ */
+ public PapyrusDragEditPartsTrackerEx(final EditPart sourceEditPart) {
+ this(sourceEditPart, true, false, false);
+ }
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param sourceEditPart
+ * @param snapOnCorners
+ * @param snapOnMiddles
+ * @param snapOnCenter
+ */
+ public PapyrusDragEditPartsTrackerEx(final EditPart sourceEditPart, final boolean snapOnCorners, final boolean snapOnMiddles, final boolean snapOnCenter) {
+ super(sourceEditPart);
+ this.snapOnCorners = snapOnCorners;
+ this.snapOnMiddles = snapOnMiddles;
+ this.snapOnCenter = snapOnCenter;
+ }
+
+ /**
+ * This method can be overridden by clients to customize the snapping
+ * behavior.
+ *
+ * @param request
+ * the <code>ChangeBoundsRequest</code> from which the move delta
+ * can be extracted and updated
+ * @since 3.4
+ */
+ @Override
+ @SuppressWarnings({ "unchecked" })
+ protected void snapPoint(ChangeBoundsRequest request) {
+ if (getSnapToHelper() != null && request.isSnapToEnabled() && request.getEditParts().size() > 0) {
+
+ // test to know if we are moving using keyboard
+ if (!getCurrentInput().isAnyButtonDown()) {
+ calculateSnapPointFromArrowKey(request);
+ return;
+ }
+ int restrictedDirection = 0;
+ restrictedDirection = restrictedDirection | PositionConstants.EAST;
+ restrictedDirection = restrictedDirection | PositionConstants.WEST;
+ restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
+ restrictedDirection = restrictedDirection | PositionConstants.NORTH;
+ request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
+
+ final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
+ if (this.snapOnCorners) {
+ distVSPoint.putAll(getCornerDistances(request));
+ }
+
+ if (this.snapOnMiddles) {
+ distVSPoint.putAll(getMiddleDistances(request));
+ }
+
+ if (this.snapOnCenter) {
+ distVSPoint.putAll(getCenterDistances(request));
+ }
+
+ final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
+ if (distances.size() > 0) {
+ double min = distances.get(0);
+ for (int i = 1; i < distances.size() - 1; i++) {
+ min = Math.min(min, distances.get(i));
+ }
+ request.setMoveDelta(distVSPoint.get(min));
+ }
+ }
+ }
+
+ /**
+ *
+ * @param request
+ * a move request
+ * @return
+ * the restricted direction for the request
+ */
+ protected final int getRestrictedDirection(final ChangeBoundsRequest request) {
+ int restrictedDirection = 0;
+ final Point delta = request.getMoveDelta();
+ if (delta.x > 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.EAST;
+ restrictedDirection = restrictedDirection | PositionConstants.WEST;
+ }
+ if (delta.x < 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.EAST;
+ restrictedDirection = restrictedDirection | PositionConstants.WEST;
+ }
+ if (delta.y > 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
+ restrictedDirection = restrictedDirection | PositionConstants.NORTH;
+ }
+ if (delta.y < 0) {
+ restrictedDirection = restrictedDirection | PositionConstants.SOUTH;
+ restrictedDirection = restrictedDirection | PositionConstants.NORTH;
+ }
+ return restrictedDirection;
+ }
+
+ /**
+ *
+ * @param request
+ * the move request
+ */
+ @SuppressWarnings("unchecked")
+ protected void calculateSnapPointFromArrowKey(final ChangeBoundsRequest request) {
+ if (request.getEditParts().size() == 0) {
+ return;
+ }
+ final Object ep = request.getEditParts().get(0);
+ if (!(ep instanceof IGraphicalEditPart)) {
+ return;
+ }
+ final RootEditPart root = ((IGraphicalEditPart) ep).getRoot();
+ if (!(root instanceof DiagramRootEditPart)) {
+ return;
+ }
+ final double gridSpacing = ((DiagramRootEditPart) root).getGridSpacing();
+ int max = (int) (1 + gridSpacing);
+ int restrictedDirection = getRestrictedDirection(request);
+ final Point delta = request.getMoveDelta();
+ final Point newDelta = new Point(0, 0);
+ int newMove = 0;
+ while (newMove < max) {
+ newMove++;
+ if (delta.x > 0) {
+ newDelta.x = newMove + delta.x;
+ }
+ if (delta.x < 0) {
+ newDelta.x = (-newMove) + delta.x;
+ }
+ if (delta.y > 0) {
+ newDelta.y = newMove + delta.y;
+ }
+ if (delta.y < 0) {
+ newDelta.y = (-newMove) + delta.y;
+ }
+ request.setMoveDelta(newDelta);
+ request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS, restrictedDirection);
+
+ final Map<Double, PrecisionPoint> distVSPoint = new HashMap<Double, PrecisionPoint>();
+ if (this.snapOnCorners) {
+ distVSPoint.putAll(getCornerDistances(request));
+ }
+
+ if (this.snapOnMiddles) {
+ distVSPoint.putAll(getMiddleDistances(request));
+ }
+
+ if (this.snapOnCenter) {
+ distVSPoint.putAll(getCenterDistances(request));
+ }
+
+ final List<Double> distances = new ArrayList<Double>(distVSPoint.keySet());
+ if (distances.size() > 0) {
+ double min = distances.get(0);
+ // We look for the minus distance
+ for (int i = 1; i < distances.size() - 1; i++) {
+ min = Math.min(min, distances.get(i));
+ }
+ final Point minPoint = distVSPoint.get(min);
+ // the distance can't be null
+ if (minPoint.x != 0 || minPoint.y != 0) {
+ // the calculate move must be in the same direction than the keyboard move
+ if (Integer.signum(minPoint.x) == Integer.signum(delta.x) && Integer.signum(minPoint.y) == Integer.signum(delta.y)) {
+ request.setMoveDelta(distVSPoint.get(min));
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ * a map with the couple distance and delta point to anchor by the corner of the figure
+ */
+ protected Map<Double, PrecisionPoint> getCornerDistances(final ChangeBoundsRequest request) {
+ final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+ final Point moveDelta = request.getMoveDelta();
+ PrecisionRectangle jointRect = getCompoundSourceRectangle();
+ jointRect.translate(moveDelta);
+
+ // calculate the delta to anchor on the top left corner
+ final PrecisionPoint topLeftCornerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectTopLeft = getSourceRectangle();
+ baseRectTopLeft.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectTopLeft, jointRect }, topLeftCornerDelta);
+
+ // FIXME : add preferences and re-activate this part of the code
+
+ // //calculate the delta to anchor on the top right corner
+ // final PrecisionPoint topRightCornerDelta = new PrecisionPoint(moveDelta);
+ // final PrecisionRectangle baseRectTopRight = getSourceRectangle();
+ // baseRectTopRight.setX(baseRectTopRight.x + baseRectTopRight.width);
+ // baseRectTopRight.translate(moveDelta);
+ // getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[]{ baseRectTopRight, jointRect }, topRightCornerDelta);
+ //
+ // //calculate the delta to anchor on the bottom left corner
+ // final PrecisionPoint bottomLeftCornerDelta = new PrecisionPoint(moveDelta);
+ // final PrecisionRectangle baseRectBottomLeft = getSourceRectangle();
+ // baseRectBottomLeft.setY(baseRectBottomLeft.y + baseRectBottomLeft.height);
+ // baseRectBottomLeft.translate(moveDelta);
+ // getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[]{ baseRectBottomLeft, jointRect }, bottomLeftCornerDelta);
+ //
+ // //calculate the delta to anchor on the bottom right corner
+ // final PrecisionPoint bottomRightCornerDelta = new PrecisionPoint(moveDelta);
+ // final PrecisionRectangle baseRectBottomRight = getSourceRectangle();
+ // baseRectBottomRight.setX(baseRectBottomRight.x + baseRectBottomRight.width);
+ // baseRectBottomRight.setY(baseRectBottomRight.y + baseRectBottomRight.height);
+ // baseRectBottomRight.translate(moveDelta);
+ // getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[]{ baseRectBottomRight, jointRect }, bottomRightCornerDelta);
+
+ final Point ref = baseRectTopLeft.getTopLeft();
+ distVSPoints.put(distance(ref, topLeftCornerDelta), topLeftCornerDelta);
+ // distVSPoints.put(distance(ref, topRightCornerDelta), topRightCornerDelta);
+ // distVSPoints.put(distance(ref, bottomLeftCornerDelta), bottomLeftCornerDelta);
+ // distVSPoints.put(distance(ref, bottomRightCornerDelta), bottomRightCornerDelta);
+ }
+ return distVSPoints;
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ * a map with the couple distance and delta point to anchor by the middle of each side of the figure
+ */
+ protected Map<Double, PrecisionPoint> getMiddleDistances(final ChangeBoundsRequest request) {
+ final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+ final Point moveDelta = request.getMoveDelta();
+
+ PrecisionRectangle jointRect = getCompoundSourceRectangle();
+ jointRect.translate(moveDelta);
+ // calculate the delta to anchor on the middle top point
+ final PrecisionPoint middleTopDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleTop = getSourceRectangle();
+ baseRectMiddleTop.setPreciseLocation(baseRectMiddleTop.preciseX() + (baseRectMiddleTop.preciseWidth() / 2), baseRectMiddleTop.preciseY());
+ baseRectMiddleTop.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleTop, jointRect }, middleTopDelta);
+
+ // calculate the delta to anchor on the middle left point
+ final PrecisionPoint middleLeftDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleLeft = getSourceRectangle();
+ baseRectMiddleLeft.setPreciseLocation(baseRectMiddleLeft.preciseX(), baseRectMiddleLeft.preciseY() + (baseRectMiddleLeft.preciseWidth() / 2));
+ baseRectMiddleLeft.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleLeft, jointRect }, middleLeftDelta);
+
+ // calculate the delta to anchor on the middle right point
+ final PrecisionPoint middleRightDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleRight = getSourceRectangle();
+ baseRectMiddleRight.setPreciseLocation(baseRectMiddleRight.preciseX() + baseRectMiddleRight.preciseWidth(), baseRectMiddleRight.preciseY() + (baseRectMiddleRight.preciseHeight() / 2));
+ baseRectMiddleRight.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleRight, jointRect }, middleRightDelta);
+
+ // calculate the delta to anchor on the middle bottom
+ final PrecisionPoint middleBottomDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectMiddleBottom = getSourceRectangle();
+ baseRectMiddleBottom.setPreciseLocation(baseRectMiddleBottom.preciseX() + (baseRectMiddleBottom.preciseWidth() / 2), baseRectMiddleBottom.preciseY() + baseRectMiddleBottom.preciseHeight());
+ baseRectMiddleBottom.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectMiddleBottom, jointRect }, middleBottomDelta);
+
+ final Point ref = baseRectMiddleTop.getTopLeft();
+ distVSPoints.put(distance(ref, middleTopDelta), middleTopDelta);
+ distVSPoints.put(distance(ref, middleLeftDelta), middleLeftDelta);
+ distVSPoints.put(distance(ref, middleRightDelta), middleRightDelta);
+ distVSPoints.put(distance(ref, middleBottomDelta), middleBottomDelta);
+ }
+
+ return distVSPoints;
+ }
+
+ /**
+ *
+ * @param request
+ * @return
+ * a map with the couple distance and delta point to anchor by the center of the figure
+ */
+ protected Map<Double, PrecisionPoint> getCenterDistances(final ChangeBoundsRequest request) {
+ final Map<Double, PrecisionPoint> distVSPoints = new HashMap<Double, PrecisionPoint>();
+ if (getSnapToHelper() != null && request.isSnapToEnabled()) {
+ final Point moveDelta = request.getMoveDelta();
+
+ PrecisionRectangle jointRect = getCompoundSourceRectangle();
+ jointRect.translate(moveDelta);
+ // calculate the delta to anchor on the middle top point
+ final PrecisionPoint centerDelta = new PrecisionPoint(moveDelta);
+ final PrecisionRectangle baseRectCenter = getSourceRectangle();
+ baseRectCenter.setPreciseLocation(baseRectCenter.preciseX() + (baseRectCenter.preciseWidth() / 2), baseRectCenter.preciseY() + (baseRectCenter.preciseHeight() / 2));
+ baseRectCenter.translate(moveDelta);
+ getSnapToHelper().snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRectCenter, jointRect }, centerDelta);
+
+ final Point ref = baseRectCenter.getTopLeft();
+ distVSPoints.put(distance(ref, centerDelta), centerDelta);
+ }
+
+ return distVSPoints;
+ }
+
+ /**
+ *
+ * @param pt1
+ * a first point
+ * @param pt2
+ * the second point
+ * @return
+ * the distance between the two points
+ */
+ protected final double distance(final Point pt1, final Point pt2) {
+ double deltaX = pt1.preciseX() - pt2.preciseX();
+ double deltaY = pt1.preciseY() - pt2.preciseY();
+ return Math.hypot(deltaX, deltaY);
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java
index 31be900c6af..a0c15208503 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/SnapUtils.java
@@ -1,59 +1,59 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.snap;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.SWT;
-
-
-public class SnapUtils {
-
- private SnapUtils() {
- // to prevent instanciation
- }
-
- /**
- * Key modifier for centered resizing. It's ALT on the Mac and MOD1 on all
- * other platforms.
- */
- public static final int MODIFIER_CENTERED_RESIZE;
-
- static {
- if (Platform.OS_MACOSX.equals(Platform.getOS())) {
- MODIFIER_CENTERED_RESIZE = SWT.ALT;
- } else {
- MODIFIER_CENTERED_RESIZE = SWT.MOD1;
- }
- }
-
- /**
- * Key modifier for constrained resizing. It's SHIFT on all platforms.
- */
- public static final int MODIFIER_CONSTRAINED_RESIZE = SWT.SHIFT;
-
- /**
- * Key modifier for ignoring snap while dragging. It's CTRL on Mac, and ALT
- * on all other platforms.
- */
- public static final int MODIFIER_NO_SNAPPING;
-
- static {
- if (Platform.OS_MACOSX.equals(Platform.getOS())) {
- MODIFIER_NO_SNAPPING = SWT.CTRL;
- } else {
- MODIFIER_NO_SNAPPING = SWT.ALT;
- }
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.snap;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swt.SWT;
+
+
+public class SnapUtils {
+
+ private SnapUtils() {
+ // to prevent instanciation
+ }
+
+ /**
+ * Key modifier for centered resizing. It's ALT on the Mac and MOD1 on all
+ * other platforms.
+ */
+ public static final int MODIFIER_CENTERED_RESIZE;
+
+ static {
+ if (Platform.OS_MACOSX.equals(Platform.getOS())) {
+ MODIFIER_CENTERED_RESIZE = SWT.ALT;
+ } else {
+ MODIFIER_CENTERED_RESIZE = SWT.MOD1;
+ }
+ }
+
+ /**
+ * Key modifier for constrained resizing. It's SHIFT on all platforms.
+ */
+ public static final int MODIFIER_CONSTRAINED_RESIZE = SWT.SHIFT;
+
+ /**
+ * Key modifier for ignoring snap while dragging. It's CTRL on Mac, and ALT
+ * on all other platforms.
+ */
+ public static final int MODIFIER_NO_SNAPPING;
+
+ static {
+ if (Platform.OS_MACOSX.equals(Platform.getOS())) {
+ MODIFIER_NO_SNAPPING = SWT.CTRL;
+ } else {
+ MODIFIER_NO_SNAPPING = SWT.ALT;
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/AbstractTool.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/AbstractTool.java
index 400502fc274..7796e04a892 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/AbstractTool.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/AbstractTool.java
@@ -1,1788 +1,1788 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
-
-import java.beans.IntrospectionException;
-import java.beans.Introspector;
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.gef.DragTracker;
-import org.eclipse.gef.EditDomain;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.LayerConstants;
-import org.eclipse.gef.MouseWheelHandler;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.Tool;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CommandStackEvent;
-import org.eclipse.gef.commands.CommandStackEventListener;
-import org.eclipse.gef.editparts.LayerManager;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.dnd.DragSourceEvent;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.TraverseEvent;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Scrollable;
-
-/**
- * The base implementation for {@link Tool}s. The base implementation provides a
- * framework for a <EM>state machine</EM> which processes mouse and keyboard
- * input. The state machine consists of a series of states identified by <code>int</code>s. Each mouse or keyboard event results in a transition,
- * sometimes to the same state in which the input was received. The interesting
- * transitions have corresponding actions assigned to them, such as {@link #handleDragStarted()}.
- * <P>
- * The base implementation performs <EM>no</em> state transitions by default, but does route events to different method handlers based on state. It is up to subclasses to set the appropriate states.
- * <P>
- * There are two broad "categories" of methods on AbstractTool. There are the methods defined on the {@link Tool} interface which handle the job of receiving raw user input. For example, {@link #mouseDrag(MouseEvent, EditPartViewer)}. Then, there are the
- * methods which correspond to higher-level interpretation of these events, such as {@link #handleDragInProgress()}, which is called from <code>mouseMove(...)</code>, but <em>only</em> when the drag threshold has been passed. These methods are generally more
- * subclass-friendly. Subclasses should <em>not</em> override the methods which receive raw input.
- */
-public abstract class AbstractTool extends org.eclipse.gef.util.FlagSupport
- implements Tool, RequestConstants {
-
- /**
- * The property to be used in {@link #setProperties(Map)} for {@link #setUnloadWhenFinished(boolean)}
- */
- public static final Object PROPERTY_UNLOAD_WHEN_FINISHED = "unloadWhenFinished"; //$NON-NLS-1$
-
- private static final int DRAG_THRESHOLD = 5;
- private static final int FLAG_ACTIVE = 8;
- private static final int FLAG_HOVER = 2;
- private static final int FLAG_PAST_THRESHOLD = 1;
- private static final int FLAG_UNLOAD = 4;
- {
- setFlag(FLAG_UNLOAD, true);
- }
-
- /**
- * The highest-bit flag being used.
- */
- protected static final int MAX_FLAG = 8;
-
- /**
- * The maximum state flag defined by this class
- */
- protected static final int MAX_STATE = 32;
-
- /**
- * constant used for mouse button 1.
- *
- * @deprecated Use {@link SWT#BUTTON1} instead.
- */
- @Deprecated
- protected static final int MOUSE_BUTTON1 = SWT.BUTTON1;
- /**
- * constant used for mouse button 2.
- *
- * @deprecated Use {@link SWT#BUTTON2} instead.
- */
- @Deprecated
- protected static final int MOUSE_BUTTON2 = SWT.BUTTON2;
- /**
- * constant used for mouse button 3.
- *
- * @deprecated Use {@link SWT#BUTTON3} instead.
- */
- @Deprecated
- protected static final int MOUSE_BUTTON3 = SWT.BUTTON3;
- /**
- * constant used to indicate any of the mouse buttons.
- *
- * @deprecated Use {@link SWT#BUTTON_MASK} instead.
- */
- @Deprecated
- protected static final int MOUSE_BUTTON_ANY = SWT.BUTTON_MASK;
-
- /**
- * The state indicating that the keyboard is being used to perform a drag
- * that is normally done using the mouse.
- */
- protected static final int STATE_ACCESSIBLE_DRAG = 16;
-
- /**
- * The state indicating that a keyboard drag is in progress. The threshold
- * for keyboard drags is non-existent, so this state would be entered very
- * quickly.
- */
- protected static final int STATE_ACCESSIBLE_DRAG_IN_PROGRESS = 32;
-
- /**
- * The state indicating that one or more buttons are pressed, but the user
- * has not moved past the drag threshold. Many tools will do nothing during
- * this state but wait until {@link #STATE_DRAG_IN_PROGRESS} is entered.
- */
- protected static final int STATE_DRAG = 2;
-
- /**
- * The state indicating that the drag detection theshold has been passed,
- * and a drag is in progress.
- */
- protected static final int STATE_DRAG_IN_PROGRESS = 4;
-
- /**
- * The first state that a tool is in. The tool will generally be in this
- * state immediately following {@link #activate()}.
- */
- protected static final int STATE_INITIAL = 1;
-
- /**
- * The state indicating that an input event has invalidated the interaction.
- * For example, during a mouse drag, pressing additional mouse button might
- * invalidate the drag.
- */
- protected static final int STATE_INVALID = 8;
-
- /**
- * The final state for a tool to be in. Once a tool reaches this state, it
- * will not change states until it is activated() again.
- */
- protected static final int STATE_TERMINAL = 1 << 30;
-
- /**
- * Key modifier for ignoring snap while dragging. It's CTRL on Mac, and ALT
- * on all other platforms.
- */
- protected static final int MODIFIER_NO_SNAPPING;
-
- static {
- if (Platform.OS_MACOSX.equals(Platform.getOS())) {
- MODIFIER_NO_SNAPPING = SWT.CTRL;
- } else {
- MODIFIER_NO_SNAPPING = SWT.ALT;
- }
- }
-
- private long accessibleBegin;
-
- private int accessibleStep;
- private Command command;
-
- private CommandStackEventListener commandStackListener = new CommandStackEventListener() {
- @Override
- public void stackChanged(CommandStackEvent event) {
- if (event.isPreChangeEvent()) {
- handleCommandStackChanged();
- }
- }
- };
- private Input current;
- private EditPartViewer currentViewer;
- private Cursor defaultCursor, disabledCursor;
- private EditDomain domain;
- private List operationSet;
- private int startX, startY, state;
-
- boolean acceptAbort(KeyEvent e) {
- return e.character == SWT.ESC;
- }
-
- /**
- * Returns true if the event corresponds to an arrow key with the
- * appropriate modifiers and if the system is in a state where the arrow key
- * should be accepted.
- *
- * @param e
- * the key event
- * @return true if the arrow key should be accepted by this tool
- * @since 3.4
- */
- protected boolean acceptArrowKey(KeyEvent e) {
- int key = e.keyCode;
- if (!(isInState(STATE_INITIAL | STATE_ACCESSIBLE_DRAG
- | STATE_ACCESSIBLE_DRAG_IN_PROGRESS))) {
- return false;
- }
- return (key == SWT.ARROW_UP) || (key == SWT.ARROW_RIGHT)
- || (key == SWT.ARROW_DOWN) || (key == SWT.ARROW_LEFT);
- }
-
- boolean acceptDragCommit(KeyEvent e) {
- return isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)
- && e.character == 13;
- }
-
- int accGetStep() {
- return accessibleStep;
- }
-
- void accStepIncrement() {
- if (accessibleBegin == -1) {
- accessibleBegin = new Date().getTime();
- accessibleStep = 1;
- } else {
- accessibleStep = 4;
- long elapsed = new Date().getTime() - accessibleBegin;
- if (elapsed > 1000) {
- accessibleStep = Math.min(16, (int) (elapsed / 150));
- }
- }
- }
-
- void accStepReset() {
- accessibleBegin = -1;
- }
-
- /**
- * Activates the tool. Any initialization should be performed here. This
- * method is called when a tool is selected.
- *
- * @see #deactivate()
- */
- @Override
- public void activate() {
- resetFlags();
- accessibleBegin = -1;
- getCurrentInput().verifyMouseButtons = true;
- setState(STATE_INITIAL);
- setFlag(FLAG_ACTIVE, true);
- getDomain().getCommandStack().addCommandStackEventListener(
- commandStackListener);
- }
-
- /**
- * Convenience method to add the given figure to the feedback layer.
- *
- * @param figure
- * the feedback being added
- */
- protected void addFeedback(IFigure figure) {
- LayerManager lm = (LayerManager) getCurrentViewer()
- .getEditPartRegistry().get(LayerManager.ID);
- if (lm == null) {
- return;
- }
- lm.getLayer(LayerConstants.FEEDBACK_LAYER).add(figure);
- }
-
- /**
- * This method is invoked from {@link #setProperties(Map)}. Sub-classes can
- * override to add support for more properties. This method should fail
- * silently in case of any error.
- * <p>
- * AbstractTool uses introspection to match any keys with properties. For instance, the key "defaultCursor" would lead to the invocation of {@link #setDefaultCursor(Cursor)} with the provided value.
- *
- * @param key
- * the key; may be <code>null</code>
- * @param value
- * the new value
- * @since 3.1
- * @see #setProperties(Map)
- */
- protected void applyProperty(Object key, Object value) {
- if (PROPERTY_UNLOAD_WHEN_FINISHED.equals(key)) {
- if (value instanceof Boolean) {
- setUnloadWhenFinished(((Boolean) value).booleanValue());
- }
- return;
- }
-
- if (!(key instanceof String)) {
- return;
- }
-
- try {
- PropertyDescriptor[] descriptors = Introspector.getBeanInfo(
- getClass(), Introspector.IGNORE_ALL_BEANINFO)
- .getPropertyDescriptors();
- PropertyDescriptor property = null;
- for (int i = 0; i < descriptors.length; i++) {
- if (descriptors[i].getName().equals(key)) {
- property = descriptors[i];
- break;
- }
- }
- if (property != null) {
- Method setter = property.getWriteMethod();
- // setter.setAccessible(true);
- setter.invoke(this, new Object[] { value });
- }
- } catch (IntrospectionException ie) {
- } catch (IllegalAccessException iae) {
- } catch (InvocationTargetException ite) {
- } catch (SecurityException se) {
- }
- }
-
- /**
- * Returns the appropriate cursor for the tools current state. If the tool
- * is in its terminal state, <code>null</code> is returned. Otherwise,
- * either the default or disabled cursor is returned, based on the existence
- * of a current command, and whether that current command is executable.
- * <P>
- * Subclasses may override or extend this method to calculate the appropriate cursor based on other conditions.
- *
- * @see #getDefaultCursor()
- * @see #getDisabledCursor()
- * @see #getCurrentCommand()
- * @return <code>null</code> or a cursor to be displayed.
- */
- protected Cursor calculateCursor() {
- if (isInState(STATE_TERMINAL)) {
- return null;
- }
- Command command = getCurrentCommand();
- if (command == null || !command.canExecute()) {
- return getDisabledCursor();
- }
- return getDefaultCursor();
- }
-
- /**
- * Added for compatibility. {@link DragTracker#commitDrag()} was added for
- * accessibility reasons. Since all tool implementations must inherit from
- * this base class, then implementing this method here avoids breaking
- * subclasses that implemented the {@link DragTracker} interface.
- */
- public void commitDrag() {
- }
-
- /**
- * Returns a new List of editparts that this tool is operating on. This
- * method is called once during {@link #getOperationSet()}, and its result
- * is cached.
- * <P>
- * By default, the operations set is the current viewer's entire selection. Subclasses may override this method to filter or alter the operation set as necessary.
- *
- * @return a list of editparts being operated on
- */
- protected List createOperationSet() {
- return new ArrayList(getCurrentViewer().getSelectedEditParts());
- }
-
- /**
- * Deactivates the tool. This method is called whenever the user switches to
- * another tool. Use this method to do some clean-up when the tool is
- * switched. The abstract tool allows cursors for viewers to be changed.
- * When the tool is deactivated it must revert to normal the cursor of the
- * last tool it changed.
- *
- * @see #activate()
- */
- @Override
- public void deactivate() {
- setFlag(FLAG_ACTIVE, false);
- setViewer(null);
- setCurrentCommand(null);
- setState(STATE_TERMINAL);
- operationSet = null;
- current = null;
- getDomain().getCommandStack().removeCommandStackEventListener(
- commandStackListener);
- }
-
- /**
- * Prints a string in the GEF Debug console if the Tools debug option is
- * selected.
- *
- * @param message
- * a message for the debug trace tool
- * @deprecated
- */
- @Deprecated
- protected void debug(String message) {
- }
-
- /**
- * Executes the given command on the command stack.
- *
- * @since 3.1
- * @param command
- * the command to execute
- */
- protected void executeCommand(Command command) {
- getDomain().getCommandStack().removeCommandStackEventListener(
- commandStackListener);
- try {
- getDomain().getCommandStack().execute(command);
- } finally {
- getDomain().getCommandStack().addCommandStackEventListener(
- commandStackListener);
- }
- }
-
- /**
- * Execute the currently active command.
- */
- protected void executeCurrentCommand() {
- Command curCommand = getCurrentCommand();
- if (curCommand != null && curCommand.canExecute()) {
- executeCommand(curCommand);
- }
- setCurrentCommand(null);
- }
-
- /**
- * Called when a viewer that the editor controls gains focus.
- *
- * @param event
- * The SWT focus event
- * @param viewer
- * The viewer that the focus event is over.
- */
- @Override
- public void focusGained(FocusEvent event, EditPartViewer viewer) {
- setViewer(viewer);
- handleFocusGained();
- }
-
- /**
- * Called when a viewer that the editor controls loses focus.
- *
- * @param event
- * The SWT focus event
- * @param viewer
- * The viewer that the focus event is over.
- */
- @Override
- public void focusLost(FocusEvent event, EditPartViewer viewer) {
- setViewer(viewer);
- handleFocusLost();
- }
-
- /**
- * Returns a new, updated command based on the tool's current properties.
- * The default implementation returns an unexecutable command. Some tools do
- * not work commands and the model, but simply change the viewer's state in
- * some way.
- *
- * @return a newly obtained command
- */
- protected Command getCommand() {
- return org.eclipse.gef.commands.UnexecutableCommand.INSTANCE;
- }
-
- /**
- * Returns the identifier of the command that is being sought. This name is
- * also the named that will be logged in the debug view.
- *
- * @return the identifier for the command
- */
- protected abstract String getCommandName();
-
- /**
- * Returns the currently cached command.
- *
- * @return the current command
- * @see #setCurrentCommand(Command)
- */
- protected Command getCurrentCommand() {
- return command;
- }
-
- /**
- * Returns the input object encapsulating the current mouse and keyboard
- * state.
- *
- * @return the current input
- */
- protected Input getCurrentInput() {
- if (current == null) {
- current = new Input();
- }
- return current;
- }
-
- /**
- * Return the viewer that the tool is currently receiving input from, or <code>null</code>. The last viewer to dispatch an event is defined as the
- * current viewer. Current viewer is automatically updated as events are
- * received, and is set to <code>null</code> on <code>deactivate()</code>.
- *
- * @return the current viewer
- */
- protected EditPartViewer getCurrentViewer() {
- return currentViewer;
- }
-
- /**
- * Returns the debug name for this tool.
- *
- * @return the debug name
- */
- protected String getDebugName() {
- return getClass().getName();
- }
-
- /**
- * Returns a String representation of the given state for debug purposes.
- *
- * @param state
- * the state
- * @return the string for the given state
- */
- protected String getDebugNameForState(int state) {
- switch (state) {
- case STATE_INITIAL:
- return "Initial State";//$NON-NLS-1$
- case STATE_DRAG:
- return "Drag State";//$NON-NLS-1$
- case STATE_DRAG_IN_PROGRESS:
- return "Drag In Progress State";//$NON-NLS-1$
- case STATE_INVALID:
- return "Invalid State"; //$NON-NLS-1$
- case STATE_TERMINAL:
- return "Terminal State"; //$NON-NLS-1$
- case STATE_ACCESSIBLE_DRAG:
- return "Accessible Drag"; //$NON-NLS-1$
- case STATE_ACCESSIBLE_DRAG_IN_PROGRESS:
- return "Accessible Drag In Progress"; //$NON-NLS-1$
- }
- return "Unknown state:";//$NON-NLS-1$
- }
-
- /**
- * Returns the cursor used under normal conditions.
- *
- * @see #setDefaultCursor(Cursor)
- * @return the default cursor
- */
- protected Cursor getDefaultCursor() {
- return defaultCursor;
- }
-
- /**
- * Returns the cursor used under abnormal conditions.
- *
- * @see #calculateCursor()
- * @see #setDisabledCursor(Cursor)
- * @return the disabled cursor
- */
- protected Cursor getDisabledCursor() {
- if (disabledCursor != null) {
- return disabledCursor;
- }
- return getDefaultCursor();
- }
-
- /**
- * Returns the EditDomain. A tool is told its EditDomain when it becomes
- * active. A tool may need to know its edit domain prior to receiving any
- * events from any of that domain's viewers.
- *
- * @return the editdomain
- */
- protected EditDomain getDomain() {
- return domain;
- }
-
- /**
- * Return the number of pixels that the mouse has been moved since that drag
- * was started. The drag start is determined by where the mouse button was
- * first pressed.
- *
- * @see #getStartLocation()
- * @return the drag delta
- */
- protected Dimension getDragMoveDelta() {
- return getLocation().getDifference(getStartLocation());
- }
-
- /**
- * Returns the current x, y position of the mouse cursor.
- *
- * @return the mouse location
- */
- protected Point getLocation() {
- return new Point(getCurrentInput().getMouseLocation());
- }
-
- /**
- * Lazily creates and returns the list of editparts on which the tool
- * operates. The list is initially <code>null</code>, in which case {@link #createOperationSet()} is called, and its results cached until the
- * tool is deactivated.
- *
- * @return the operation set.
- */
- protected List getOperationSet() {
- if (operationSet == null) {
- operationSet = createOperationSet();
- }
- return operationSet;
- }
-
- /**
- * Returns the starting mouse location for the current tool operation. This
- * is typically the mouse location where the user first pressed a mouse
- * button. This is important for tools that interpret mouse drags.
- *
- * @return the start location
- */
- protected Point getStartLocation() {
- return new Point(startX, startY);
- }
-
- /**
- * Returns the tool's current state.
- *
- * @return the current state
- */
- protected int getState() {
- return state;
- }
-
- /**
- * Called when the mouse button has been pressed. By default, nothing
- * happens and <code>false</code> is returned. Subclasses may override this
- * method to interpret the meaning of a mouse down. Returning <code>true</code> indicates that the button down was handled in some way.
- *
- * @param button
- * which button went down
- * @return <code>true</code> if the buttonDown was handled
- */
- protected boolean handleButtonDown(int button) {
- return false;
- }
-
- /**
- * Called when the mouse button has been released. By default, nothing
- * happens and <code>false</code> is returned. Subclasses may override this
- * method to interpret the mouse up. Returning <code>true</code> indicates
- * that the mouse up was handled in some way.
- *
- * @see #mouseUp(MouseEvent, EditPartViewer)
- * @param button
- * the button being released
- * @return <code>true</code> if the button up was handled
- */
- protected boolean handleButtonUp(int button) {
- return false;
- }
-
- /**
- * Called when the command stack has changed, for instance, when a delete or
- * undo command has been executed. By default, state is set to <code>STATE_INVALID</code> and handleInvalidInput is called. Subclasses
- * may override this method to change what happens when the command stack
- * changes. Returning <code>true</code> indicates that the change was
- * handled in some way.
- *
- * @return <code>true</code> if the change was handled in some way
- */
- protected boolean handleCommandStackChanged() {
- if (!isInState(STATE_INITIAL | STATE_INVALID)) {
- setState(STATE_INVALID);
- handleInvalidInput();
- return true;
- }
- return false;
- }
-
- /**
- * Called when a mouse double-click occurs. By default, nothing happens and <code>false</code> is returned. Subclasses may override this method to
- * interpret double-clicks. Returning <code>true</code> indicates that the
- * event was handled in some way.
- *
- * @param button
- * which button was double-clicked
- * @return <code>true</code> if the event was handled
- * @see #mouseDoubleClick(MouseEvent, EditPartViewer)
- */
- protected boolean handleDoubleClick(int button) {
- return false;
- }
-
- /**
- * Called whenever the mouse is being dragged. This method continues to be
- * called even once {@link #handleDragInProgress()} starts getting called.
- * By default, nothing happens, and <code>false</code> is returned.
- * Subclasses may override this method to interpret a drag. Returning <code>true</code> indicates that the drag was handled in some way.
- *
- * @return <code>true</code> if the drag is handled
- * @see #mouseDrag(MouseEvent, EditPartViewer)
- */
- protected boolean handleDrag() {
- return false;
- }
-
- /**
- * Called whenever a mouse is being dragged and the drag threshold has been
- * exceeded. Prior to the drag threshold being exceeded, only {@link #handleDrag()} is called. This method gets called repeatedly for
- * every mouse move during the drag. By default, nothing happens and <code>false</code> is returned. Subclasses may override this method to
- * interpret the drag. Returning <code>true</code> indicates that the drag
- * was handled.
- *
- * @see #movedPastThreshold()
- * @see #mouseDrag(MouseEvent, EditPartViewer)
- * @return <code>true</code> if the drag was handled
- */
- protected boolean handleDragInProgress() {
- return false;
- }
-
- /**
- * Called only one time during a drag when the drag threshold has been
- * exceeded. By default, nothing happens and <code>false</code> is returned.
- * Subclasses may override to interpret the drag starting. Returning <code>true</code> indicates that the event was handled.
- *
- * @see #movedPastThreshold()
- * @see #mouseDrag(MouseEvent, EditPartViewer)
- * @return true if the drag starting was handled
- */
- protected boolean handleDragStarted() {
- return false;
- }
-
- /**
- * Called when the current tool operation is to be completed. In other
- * words, the "state machine" and has accepted the sequence of input (i.e.
- * the mouse gesture). By default, the tool will either reactivate itself,
- * or ask the edit domain to load the default tool.
- * <P>
- * Subclasses should extend this method to first do whatever it is that the tool does, and then call <code>super</code>.
- *
- * @see #unloadWhenFinished()
- */
- protected void handleFinished() {
- if (unloadWhenFinished()) {
- getDomain().loadDefaultTool();
- } else {
- reactivate();
- }
- }
-
- /**
- * Handles high-level processing of a focus gained event. By default,
- * nothing happens and <code>false</code> is returned. Subclasses may
- * override this method to interpret the focus gained event. Return <code>true</code> to indicate that the event was processed.
- *
- * @see #focusGained(FocusEvent, EditPartViewer)
- * @return <code>true</code> if the event was handled
- */
- protected boolean handleFocusGained() {
- return false;
- }
-
- /**
- * Handles high-level processing of a focus lost event. By default, nothing
- * happens and <code>false</code> is returned. Subclasses may override this
- * method to interpret the focus lost event. Return <code>true</code> to
- * indicate that the event was processed.
- *
- * @see #focusLost(FocusEvent, EditPartViewer)
- * @return <code>true</code> if the event was handled
- */
- protected boolean handleFocusLost() {
- return false;
- }
-
- /**
- * Handles high-level processing of a mouse hover event. By default, nothing
- * happens and <code>false</code> is returned. Subclasses may override this
- * method to interpret the hover. Return <code>true</code> to indicate that
- * the hover was handled.
- *
- * @see #mouseHover(MouseEvent, EditPartViewer)
- * @return <code>true</code> if the hover was handled
- */
- protected boolean handleHover() {
- return false;
- }
-
- /**
- * Called when invalid input is encountered. The state does not change, so
- * the caller must set the state to {@link AbstractTool#STATE_INVALID}.
- *
- * @return <code>true</code>
- */
- protected boolean handleInvalidInput() {
- return false;
- }
-
- /**
- * Handles high-level processing of a key down event. By default, the
- * KeyEvent is checked to see if it is the ESCAPE key. If so, the domain's
- * default tool is reloaded, and <code>true</code> is returned. Subclasses
- * may extend this method to interpret additional key down events. Returns <code>true</code> if the given key down was handled.
- *
- * @see #keyDown(KeyEvent, EditPartViewer)
- * @param e
- * the key event
- * @return <code>true</code> if the key down was handled.
- */
- protected boolean handleKeyDown(KeyEvent e) {
- if (acceptAbort(e)) {
- getDomain().loadDefaultTool();
- return true;
- }
- return false;
- }
-
- /**
- * Override to process a traverse event. If the event's {@link KeyEvent#doit doit} field is set to <code>false</code>, the
- * traversal will be prevented from occurring. Otherwise, a traverse will
- * occur.
- *
- * @param event
- * the SWT traverse event
- * @since 3.1
- */
- protected void handleKeyTraversed(TraverseEvent event) {
- }
-
- /**
- * Handles high-level processing of a key up event. By default, does nothing
- * and returns <code>false</code>. Subclasses may extend this method to
- * process key up events. Returns <code>true</code> if the key up was
- * processed in some way.
- *
- * @see #keyUp(KeyEvent, EditPartViewer)
- * @param e
- * the key event
- * @return <code>true</code> if the event was handled
- */
- protected boolean handleKeyUp(KeyEvent e) {
- return false;
- }
-
- /**
- * Handles high-level processing of a mouse move. By default, does nothing
- * and returns <code>false</code>. Subclasses may extend this method to
- * process mouse moves. Returns <code>true</code> if the mouse move was
- * processed.
- *
- * @see #mouseMove(MouseEvent, EditPartViewer)
- * @return <code>true</code> if the mouse move was handled
- */
- protected boolean handleMove() {
- return false;
- }
-
- /**
- * Handles when a native drag has ended. By default, does nothing and
- * returns <code>false</code>. Subclasses may extend this method to process
- * native drags ending.
- *
- * @param event
- * the drag event
- * @return <code>true</code> if the native drag finished was handled
- */
- protected boolean handleNativeDragFinished(DragSourceEvent event) {
- return false;
- }
-
- /**
- * Handles when a native drag has started. By default, does nothing and
- * returns <code>false</code>. Subclasses may extend this method to process
- * native drag starts.
- * <P>
- * When a native drag starts, all subsequent mouse events will not be received, including the mouseUp event. The only event that will be received is the drag finished event.
- *
- * @param event
- * the drag event
- * @return <code>true</code> if the native drag start was handled
- */
- protected boolean handleNativeDragStarted(DragSourceEvent event) {
- return false;
- }
-
- /**
- * Called when the mouse enters an EditPartViewer. By default, does nothing
- * and returns <code>false</code>. Subclasses may extend this method to
- * process the viewer enter. Returns <code>true</code> to indicate if the
- * viewer entered was process in some way.
- *
- * @return <code>true</code> if the viewer entered was handled
- */
- protected boolean handleViewerEntered() {
- return false;
- }
-
- /**
- * Called when the mouse exits an EditPartViewer. By default, does nothing
- * and returns <code>false</code>. Subclasses may extend this method to
- * process viewer exits. Returns <code>true</code> to indicate if the viewer
- * exited was process in some way.
- *
- * @return <code>true</code> if the viewer exited was handled
- */
- protected boolean handleViewerExited() {
- return false;
- }
-
- /**
- * Returns <code>true</code> if the tool is active.
- *
- * @return <code>true</code> if active
- */
- protected boolean isActive() {
- return getFlag(FLAG_ACTIVE);
- }
-
- private boolean isCurrentViewerMirrored() {
- return (getCurrentViewer().getControl().getStyle() & SWT.MIRRORED) != 0;
- }
-
- /**
- * Returns <code>true</code> if the tool is hovering.
- *
- * @return <code>true</code> if hovering
- */
- protected boolean isHoverActive() {
- return getFlag(FLAG_HOVER);
- }
-
- boolean isInDragInProgress() {
- return isInState(STATE_DRAG_IN_PROGRESS
- | STATE_ACCESSIBLE_DRAG_IN_PROGRESS);
- }
-
- /*
- * Returns <code>true</code> if the current {@link Input} is synchronized
- * with the current MouseEvent.
- */
- private boolean isInputSynched(MouseEvent event) {
- Input input = getCurrentInput();
- return input.isMouseButtonDown(1) == ((event.stateMask & SWT.BUTTON1) != 0)
- && input.isMouseButtonDown(2) == ((event.stateMask & SWT.BUTTON2) != 0)
- && input.isMouseButtonDown(3) == ((event.stateMask & SWT.BUTTON3) != 0)
- && input.isMouseButtonDown(4) == ((event.stateMask & SWT.BUTTON4) != 0)
- && input.isMouseButtonDown(5) == ((event.stateMask & SWT.BUTTON5) != 0);
- }
-
- /**
- * Returns <code>true</code> if the tool is in the given state.
- *
- * @param state
- * the state being queried
- * @return <code>true</code> if the tool is in the given state
- */
- protected boolean isInState(int state) {
- return ((getState() & state) != 0);
- }
-
- /**
- * Default implementation always returns <code>true</code>. Sub-classes may
- * override.
- *
- * @param viewer
- * the viewer where the event occured
- * @return <code>true</code> if this tool is interested in events occuring
- * in the given viewer; <code>false</code> otherwise
- * @since 3.1
- */
- protected boolean isViewerImportant(EditPartViewer viewer) {
- return true;
- }
-
- /**
- * Receives a KeyDown event for the given viewer. Subclasses wanting to
- * handle this event should override {@link #handleKeyDown(KeyEvent)}.
- *
- * @param evt
- * the key event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void keyDown(KeyEvent evt, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- getCurrentInput().setInput(evt);
- handleKeyDown(evt);
- }
-
- /**
- * Receives a traversal event for the given viewer. Subclasses wanting to
- * handle this event should override {@link #handleKeyTraversed(TraverseEvent)}.
- *
- * @param event
- * the traverse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void keyTraversed(TraverseEvent event, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- getCurrentInput().setInput(event);
- handleKeyTraversed(event);
- }
-
- /**
- * Receives a KeyUp event for the given viewer. Subclasses wanting to handle
- * this event should override {@link #handleKeyUp(KeyEvent)}.
- *
- * @param evt
- * the key event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void keyUp(KeyEvent evt, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- getCurrentInput().setInput(evt);
- handleKeyUp(evt);
- }
-
- /**
- * Handles mouse double click events within a viewer. Subclasses wanting to
- * handle this event should override {@link #handleDoubleClick(int)}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void mouseDoubleClick(MouseEvent me, EditPartViewer viewer) {
- if (me.button > 5 || !isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- getCurrentInput().setInput(me);
-
- handleDoubleClick(me.button);
- }
-
- /**
- * Handles mouse down events within a viewer. Subclasses wanting to handle
- * this event should override {@link #handleButtonDown(int)}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void mouseDown(MouseEvent me, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
-
- getCurrentInput().setInput(me);
- getCurrentInput().setMouseButton(me.button, true);
-
- setStartLocation(new Point(me.x, me.y));
-
- handleButtonDown(me.button);
- }
-
- /**
- * Handles mouse drag events within a viewer. Subclasses wanting to handle
- * this event should override {@link #handleDrag()} and/or {@link #handleDragInProgress()}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void mouseDrag(MouseEvent me, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- boolean wasDragging = movedPastThreshold();
- getCurrentInput().setInput(me);
- handleDrag();
- if (movedPastThreshold()) {
- if (!wasDragging) {
- handleDragStarted();
- }
- handleDragInProgress();
- }
- }
-
- /**
- * Handles mouse hover event. within a viewer. Subclasses wanting to handle
- * this event should override {@link #handleHover()}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- *
- */
- @Override
- public void mouseHover(MouseEvent me, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- getCurrentInput().setInput(me);
- handleHover();
- }
-
- /**
- * Handles mouse moves (if the mouse button is up) within a viewer.
- * Subclasses wanting to handle this event should override {@link #handleMove()}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void mouseMove(MouseEvent me, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- if (!isInputSynched(me)) {
- boolean b1 = getCurrentInput().isMouseButtonDown(1);
- boolean b2 = getCurrentInput().isMouseButtonDown(2);
- boolean b3 = getCurrentInput().isMouseButtonDown(3);
- boolean b4 = getCurrentInput().isMouseButtonDown(4);
- boolean b5 = getCurrentInput().isMouseButtonDown(5);
- getCurrentInput().verifyMouseButtons = true;
- getCurrentInput().setInput(me);
- if (b1) {
- handleButtonUp(1);
- }
- if (b2) {
- handleButtonUp(2);
- }
- if (b3) {
- handleButtonUp(3);
- }
- if (b4) {
- handleButtonUp(4);
- }
- if (b5) {
- handleButtonUp(5);
- }
- if (getDomain().getActiveTool() != this) {
- return;
- }
- /*
- * processing one of the buttonUps may have caused the tool to
- * reactivate itself, which causes the viewer to get nulled-out. If
- * we are going to call another handleXxx method below, we must set
- * the viewer again to be paranoid.
- */
- setViewer(viewer);
- } else {
- getCurrentInput().setInput(me);
- }
- if (isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
- handleDragInProgress();
- } else {
- handleMove();
- }
- }
-
- /**
- * Handles mouse up within a viewer. Subclasses wanting to handle this event
- * should override {@link #handleButtonUp(int)}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void mouseUp(MouseEvent me, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- getCurrentInput().setInput(me);
- getCurrentInput().setMouseButton(me.button, false);
- handleButtonUp(me.button);
- }
-
- /**
- * Handles mouse-wheel scrolling for a viewer. Sub-classes may override as
- * needed. The default implementation delegates to {@link #performViewerMouseWheel(Event, EditPartViewer)} IFF the tool is
- * in the initial state. Mouse-wheel events generated at other times are
- * ignored.
- *
- * @param event
- * the SWT scroll event
- * @param viewer
- * the originating viewer
- * @see #performViewerMouseWheel(Event, EditPartViewer)
- */
- @Override
- public void mouseWheelScrolled(Event event, EditPartViewer viewer) {
- if (isInState(STATE_INITIAL)) {
- performViewerMouseWheel(event, viewer);
- }
- }
-
- /**
- * Returns <code>true</code> if the threshold has been exceeded during a
- * mouse drag.
- *
- * @return <code>true</code> if the threshold has been exceeded
- */
- protected boolean movedPastThreshold() {
- if (getFlag(FLAG_PAST_THRESHOLD)) {
- return true;
- }
- Point start = getStartLocation(), end = getLocation();
- if (Math.abs(start.x - end.x) > DRAG_THRESHOLD
- || Math.abs(start.y - end.y) > DRAG_THRESHOLD) {
- setFlag(FLAG_PAST_THRESHOLD, true);
- return true;
- }
- return false;
- }
-
- /**
- * @see org.eclipse.gef.Tool#nativeDragFinished(DragSourceEvent, EditPartViewer)
- */
- @Override
- public void nativeDragFinished(DragSourceEvent event, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- handleNativeDragFinished(event);
- }
-
- /**
- * @see org.eclipse.gef.Tool#nativeDragStarted(DragSourceEvent, EditPartViewer)
- */
- @Override
- public void nativeDragStarted(DragSourceEvent event, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- setViewer(viewer);
- handleNativeDragStarted(event);
- }
-
- /**
- * Delegates mouse-wheel event handling to registered {@link MouseWheelHandler MouseWheelHandlers} based on the given Event's
- * statemask. Does nothing if there are no matching handlers found.
- *
- * @param event
- * the SWT scroll event
- * @param viewer
- * the originating viewer
- * @since 3.1
- */
- protected void performViewerMouseWheel(Event event, EditPartViewer viewer) {
- MouseWheelHandler handler = (MouseWheelHandler) viewer
- .getProperty(MouseWheelHandler.KeyGenerator
- .getKey(event.stateMask));
- if (handler != null) {
- handler.handleMouseWheel(event, viewer);
- }
- }
-
- /**
- * Places the mouse in the viewer based on the point given. If the point
- * given is outside the viewer, then the mouse is placed in the location
- * nearest the given point but within the viewer.
- *
- * @param p
- * the point
- * @since 3.4
- */
- protected void placeMouseInViewer(Point p) {
- if (getCurrentViewer() == null) {
- return;
- }
- Control c = getCurrentViewer().getControl();
- Rectangle rect;
- if (c instanceof Scrollable) {
- rect = ((Scrollable) c).getClientArea();
- } else {
- rect = c.getBounds();
- }
- if (p.x > rect.x + rect.width - 1) {
- p.x = rect.x + rect.width - 1;
- } else if (p.x < rect.x) {
- p.x = rect.x;
- }
- if (p.y > rect.y + rect.height - 1) {
- p.y = rect.y + rect.height - 1;
- } else if (p.y < rect.y) {
- p.y = rect.y;
- }
-
- // place the mouse cursor at the calculated position within the viewer
- org.eclipse.swt.graphics.Point cursorLocation = new org.eclipse.swt.graphics.Point(
- p.x, p.y);
- cursorLocation = c.toDisplay(cursorLocation);
- // calling Display#setCursorLocation(Point) will cause an SWT.MouseMove
- // event to be dispatched as a result, so that mouseMove(MouseEvent,
- // EditPartViewer) will be triggered as a result, which will react to
- // the movement by delegating to handleMove() or handleDragInProgress().
- c.getDisplay().setCursorLocation(cursorLocation);
- }
-
- /**
- * Calls <code>deactivate()</code> and then <code>activate()</code>.
- */
- protected void reactivate() {
- // Fix for Bug# 91448
- EditPartViewer viewer = getCurrentViewer();
- deactivate();
- activate();
- if (viewer != null) {
- Control c = viewer.getControl();
- if (c != null && !c.isDisposed() && c.isFocusControl()) {
- setViewer(viewer);
- }
- }
- }
-
- /**
- * Sets the cursor being displayed to the appropriate cursor. If the tool is
- * active, the current cursor being displayed is updated by calling {@link #calculateCursor()}.
- */
- protected void refreshCursor() {
- if (isActive()) {
- setCursor(calculateCursor());
- }
- }
-
- /**
- * Releases tool capture.
- *
- * @see #setToolCapture()
- */
- protected void releaseToolCapture() {
- getCurrentViewer().setRouteEventsToEditDomain(false);
- }
-
- /**
- * Convenience method to removes a figure from the feedback layer.
- *
- * @param figure
- * the figure being removed
- */
- protected void removeFeedback(IFigure figure) {
- LayerManager lm = (LayerManager) getCurrentViewer()
- .getEditPartRegistry().get(LayerManager.ID);
- if (lm == null) {
- return;
- }
- lm.getLayer(LayerConstants.FEEDBACK_LAYER).remove(figure);
- }
-
- /**
- * Resets all stateful flags to their initial values. Subclasses should
- * extend this method to reset their own custom flags.
- */
- protected void resetFlags() {
- setFlag(FLAG_PAST_THRESHOLD, false);
- setFlag(FLAG_HOVER, false);
- }
-
- /**
- * Used to cache a command obtained from {@link #getCommand()}.
- *
- * @param c
- * the command
- * @see #getCurrentCommand()
- */
- protected void setCurrentCommand(Command c) {
- command = c;
- refreshCursor();
- }
-
- /**
- * Shows the given cursor on the current viewer.
- *
- * @param cursor
- * the cursor to display
- */
- protected void setCursor(Cursor cursor) {
- if (getCurrentViewer() != null) {
- getCurrentViewer().setCursor(cursor);
- }
- }
-
- /**
- * Sets the default cursor.
- *
- * @param cursor
- * the cursor
- * @see #getDefaultCursor()
- */
- public void setDefaultCursor(Cursor cursor) {
- if (defaultCursor == cursor) {
- return;
- }
- defaultCursor = cursor;
- refreshCursor();
- }
-
- /**
- * Sets the disabled cursor.
- *
- * @param cursor
- * the cursor
- * @see #getDisabledCursor()
- */
- public void setDisabledCursor(Cursor cursor) {
- if (disabledCursor == cursor) {
- return;
- }
- disabledCursor = cursor;
- refreshCursor();
- }
-
- /**
- * Sets the EditDomain.
- *
- * @param domain
- * the edit domain
- * @see #getDomain()
- */
- @Override
- public void setEditDomain(EditDomain domain) {
- this.domain = domain;
- }
-
- /**
- * Sets whether the hover flag is true or false. Subclasses which do
- * something on hover can use this flag to track whether they have received
- * a hover or not.
- *
- * @param value
- * whether hover is active
- */
- protected void setHoverActive(boolean value) {
- setFlag(FLAG_HOVER, value);
- }
-
- void setMouseCapture(boolean value) {
- if (getCurrentViewer() != null
- && getCurrentViewer().getControl() != null
- && !getCurrentViewer().getControl().isDisposed()) {
- getCurrentViewer().getControl().setCapture(value);
- }
- }
-
- /**
- * An example is {@link #PROPERTY_UNLOAD_WHEN_FINISHED} -> Boolean.
- * AbstractTool uses introspection to set properties that are not explicitly
- * specified. For instance, the key "defaultCursor" will cause {@link #setDefaultCursor(Cursor)} to be invoked with the given value.
- *
- * @see org.eclipse.gef.Tool#setProperties(java.util.Map)
- */
- @Override
- public void setProperties(Map properties) {
- if (properties == null) {
- return;
- }
- Iterator entries = properties.entrySet().iterator();
- while (entries.hasNext()) {
- Entry entry = (Entry) entries.next();
- applyProperty(entry.getKey(), entry.getValue());
- }
- }
-
- /**
- * Sets the start mouse location, typically for a drag operation.
- *
- * @param p
- * the start location
- */
- protected void setStartLocation(Point p) {
- startX = p.x;
- startY = p.y;
- }
-
- /**
- * Sets the tools state.
- *
- * @param state
- * the new state
- */
- protected void setState(int state) {
- this.state = state;
- }
-
- /**
- * Sets tool capture. When a tool has capture, viewers will make every
- * effort to send events through the editdomain to the tool. Therefore, the
- * default handling of some events is bypassed.
- */
- protected void setToolCapture() {
- getCurrentViewer().setRouteEventsToEditDomain(true);
- }
-
- /**
- * Setting this to <code>true</code> will cause the tool to be unloaded
- * after one operation has completed. The default value is <code>true</code> . The tool is unloaded, and the edit domains default tool will be
- * activated.
- *
- * @param value
- * whether the tool should be unloaded on completion
- */
- public void setUnloadWhenFinished(boolean value) {
- setFlag(FLAG_UNLOAD, value);
- }
-
- /**
- * Sets the active EditPartViewer. The active viewer is the viewer from
- * which the last event was received.
- *
- * @param viewer
- * the viewer
- */
- @Override
- public void setViewer(EditPartViewer viewer) {
- if (viewer == currentViewer) {
- return;
- }
-
- setCursor(null);
- currentViewer = viewer;
- if (currentViewer != null) {
- org.eclipse.swt.graphics.Point p = currentViewer.getControl()
- .toControl(Display.getCurrent().getCursorLocation());
- getCurrentInput().setMouseLocation(p.x, p.y);
- }
- refreshCursor();
- }
-
- /**
- * Returns <code>true</code> if the give state transition succeeds. This is
- * a "test and set" operation, where the tool is tested to be in the
- * specified start state, and if so, is set to the given end state. The
- * method returns the result of the first test.
- *
- * @param start
- * the start state being tested
- * @param end
- * the end state
- * @return <code>true</code> if the state transition is successful
- */
- protected boolean stateTransition(int start, int end) {
- if ((getState() & start) != 0) {
- setState(end);
- return true;
- } else {
- return false;
- }
- }
-
- /**
- * Returns <code>true</code> if the tool is set to unload when its current
- * operation is complete.
- *
- * @return <code>true</code> if the tool should be unloaded when finished
- */
- protected final boolean unloadWhenFinished() {
- return getFlag(FLAG_UNLOAD);
- }
-
- /**
- * Receives the mouse entered event. Subclasses wanting to handle this event
- * should override {@link #handleViewerEntered()}.
- * <p>
- * FEATURE in SWT: mouseExit comes after mouseEntered on the new control. Therefore, if the current viewer is not <code>null</code>, it means the exit has not been sent yet by SWT. To maintain proper ordering, GEF fakes the exit and calls
- * {@link #handleViewerExited()}. The real exit will then be ignored.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void viewerEntered(MouseEvent me, EditPartViewer viewer) {
- if (!isViewerImportant(viewer)) {
- return;
- }
- getCurrentInput().setInput(me);
- if (getCurrentViewer() != null && getCurrentViewer() != viewer) {
- handleViewerExited();
- }
- setViewer(viewer);
- handleViewerEntered();
- }
-
- /**
- * Handles the mouse exited event. Subclasses wanting to handle this event
- * should override {@link #handleViewerExited()}.
- *
- * @param me
- * the mouse event
- * @param viewer
- * the originating viewer
- */
- @Override
- public void viewerExited(MouseEvent me, EditPartViewer viewer) {
- /*
- * FEATURE in SWT. mouseExited comes after mouseEntered. So only call
- * handle exit if we didn't previously fake it on viewer entered.
- */
- if (viewer == getCurrentViewer()) {
- getCurrentInput().setInput(me);
- handleViewerExited();
- setViewer(null);
- }
- }
-
- /**
- * Allows the user to access mouse and keyboard input.
- */
- public static class Input extends org.eclipse.gef.util.FlagSupport {
- int modifiers;
- Point mouse = new Point();
- boolean verifyMouseButtons;
-
- /**
- * Returns the event modifiers. Modifiers are defined in {@link MouseEvent#stateMask}, and include things like the mouse
- * buttons and keyboard modifier keys.
- *
- * @return the event modifiers
- */
- protected int getModifiers() {
- return modifiers;
- }
-
- /**
- * Returns the current location of the mouse.
- *
- * @return the mouse location
- */
- public Point getMouseLocation() {
- return mouse;
- }
-
- /**
- * Returns <code>true</code> if the ALT key is pressed.
- *
- * @return <code>true</code> if the ALT key is pressed
- */
- public boolean isAltKeyDown() {
- return (modifiers & SWT.ALT) != 0;
- }
-
- /**
- * Returns <code>true</code> if any of the mouse buttons are pressed.
- *
- * @return <code>true</code> if any of the mouse buttons are pressed
- */
- public boolean isAnyButtonDown() {
- return getFlag(2 | 4 | 8 | 16 | 32);
- }
-
- /**
- * Returns <code>true</code> if the CTRL key is pressed.
- *
- * @return <code>true</code> of CTRL pressed
- */
- public boolean isControlKeyDown() {
- return (modifiers & SWT.CONTROL) != 0;
- }
-
- /**
- * Returns <code>true</code> if any of the given mod keys are pressed.
- *
- * @param mod
- * SWT.MOD1, SWT.MOD2, SWT.MOD3, SWT.MOD4 or any combination
- * thereof
- * @return <code>true</code> if the given mod key is pressed
- * @since 3.1
- */
- public boolean isModKeyDown(int mod) {
- return (modifiers & mod) != 0;
- }
-
- /**
- * Returns <code>true</code> if the specified button is down.
- *
- * @param which
- * which button
- * @return <code>true</code> if the button is down
- */
- public boolean isMouseButtonDown(int which) {
- return getFlag(1 << which);
- }
-
- /**
- * Returns <code>true</code> if the SHIFT key is pressed.
- *
- * @return <code>true</code> if SHIFT pressed
- */
- public boolean isShiftKeyDown() {
- return (modifiers & SWT.SHIFT) != 0;
- }
-
- /**
- * Sets the keyboard input based on the KeyEvent.
- *
- * @param ke
- * the key event providing the input
- */
- public void setInput(KeyEvent ke) {
- modifiers = ke.stateMask;
- }
-
- /**
- * Sets the mouse and keyboard input based on the MouseEvent.
- *
- * @param me
- * the mouse event providing the input
- */
- public void setInput(MouseEvent me) {
- setMouseLocation(me.x, me.y);
- modifiers = me.stateMask;
- if (verifyMouseButtons) {
- setMouseButton(1, (modifiers & SWT.BUTTON1) != 0);
- setMouseButton(2, (modifiers & SWT.BUTTON2) != 0);
- setMouseButton(3, (modifiers & SWT.BUTTON3) != 0);
- setMouseButton(4, (modifiers & SWT.BUTTON4) != 0);
- setMouseButton(5, (modifiers & SWT.BUTTON5) != 0);
- verifyMouseButtons = false;
- }
- }
-
- /**
- * Sets mouse button # <code>which</code> to be pressed if <code>state</code> is true.
- *
- * @param which
- * which button
- * @param state
- * <code>true</code> if button down
- */
- public void setMouseButton(int which, boolean state) {
- setFlag(1 << which, state);
- }
-
- /**
- * Sets the current location of the mouse
- *
- * @param x
- * x location
- * @param y
- * y location
- * @since 3.4
- */
- public void setMouseLocation(int x, int y) {
- mouse.setLocation(x, y);
- }
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
+
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.EditDomain;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.MouseWheelHandler;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.Tool;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CommandStackEvent;
+import org.eclipse.gef.commands.CommandStackEventListener;
+import org.eclipse.gef.editparts.LayerManager;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DragSourceEvent;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.TraverseEvent;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Scrollable;
+
+/**
+ * The base implementation for {@link Tool}s. The base implementation provides a
+ * framework for a <EM>state machine</EM> which processes mouse and keyboard
+ * input. The state machine consists of a series of states identified by <code>int</code>s. Each mouse or keyboard event results in a transition,
+ * sometimes to the same state in which the input was received. The interesting
+ * transitions have corresponding actions assigned to them, such as {@link #handleDragStarted()}.
+ * <P>
+ * The base implementation performs <EM>no</em> state transitions by default, but does route events to different method handlers based on state. It is up to subclasses to set the appropriate states.
+ * <P>
+ * There are two broad "categories" of methods on AbstractTool. There are the methods defined on the {@link Tool} interface which handle the job of receiving raw user input. For example, {@link #mouseDrag(MouseEvent, EditPartViewer)}. Then, there are the
+ * methods which correspond to higher-level interpretation of these events, such as {@link #handleDragInProgress()}, which is called from <code>mouseMove(...)</code>, but <em>only</em> when the drag threshold has been passed. These methods are generally more
+ * subclass-friendly. Subclasses should <em>not</em> override the methods which receive raw input.
+ */
+public abstract class AbstractTool extends org.eclipse.gef.util.FlagSupport
+ implements Tool, RequestConstants {
+
+ /**
+ * The property to be used in {@link #setProperties(Map)} for {@link #setUnloadWhenFinished(boolean)}
+ */
+ public static final Object PROPERTY_UNLOAD_WHEN_FINISHED = "unloadWhenFinished"; //$NON-NLS-1$
+
+ private static final int DRAG_THRESHOLD = 5;
+ private static final int FLAG_ACTIVE = 8;
+ private static final int FLAG_HOVER = 2;
+ private static final int FLAG_PAST_THRESHOLD = 1;
+ private static final int FLAG_UNLOAD = 4;
+ {
+ setFlag(FLAG_UNLOAD, true);
+ }
+
+ /**
+ * The highest-bit flag being used.
+ */
+ protected static final int MAX_FLAG = 8;
+
+ /**
+ * The maximum state flag defined by this class
+ */
+ protected static final int MAX_STATE = 32;
+
+ /**
+ * constant used for mouse button 1.
+ *
+ * @deprecated Use {@link SWT#BUTTON1} instead.
+ */
+ @Deprecated
+ protected static final int MOUSE_BUTTON1 = SWT.BUTTON1;
+ /**
+ * constant used for mouse button 2.
+ *
+ * @deprecated Use {@link SWT#BUTTON2} instead.
+ */
+ @Deprecated
+ protected static final int MOUSE_BUTTON2 = SWT.BUTTON2;
+ /**
+ * constant used for mouse button 3.
+ *
+ * @deprecated Use {@link SWT#BUTTON3} instead.
+ */
+ @Deprecated
+ protected static final int MOUSE_BUTTON3 = SWT.BUTTON3;
+ /**
+ * constant used to indicate any of the mouse buttons.
+ *
+ * @deprecated Use {@link SWT#BUTTON_MASK} instead.
+ */
+ @Deprecated
+ protected static final int MOUSE_BUTTON_ANY = SWT.BUTTON_MASK;
+
+ /**
+ * The state indicating that the keyboard is being used to perform a drag
+ * that is normally done using the mouse.
+ */
+ protected static final int STATE_ACCESSIBLE_DRAG = 16;
+
+ /**
+ * The state indicating that a keyboard drag is in progress. The threshold
+ * for keyboard drags is non-existent, so this state would be entered very
+ * quickly.
+ */
+ protected static final int STATE_ACCESSIBLE_DRAG_IN_PROGRESS = 32;
+
+ /**
+ * The state indicating that one or more buttons are pressed, but the user
+ * has not moved past the drag threshold. Many tools will do nothing during
+ * this state but wait until {@link #STATE_DRAG_IN_PROGRESS} is entered.
+ */
+ protected static final int STATE_DRAG = 2;
+
+ /**
+ * The state indicating that the drag detection theshold has been passed,
+ * and a drag is in progress.
+ */
+ protected static final int STATE_DRAG_IN_PROGRESS = 4;
+
+ /**
+ * The first state that a tool is in. The tool will generally be in this
+ * state immediately following {@link #activate()}.
+ */
+ protected static final int STATE_INITIAL = 1;
+
+ /**
+ * The state indicating that an input event has invalidated the interaction.
+ * For example, during a mouse drag, pressing additional mouse button might
+ * invalidate the drag.
+ */
+ protected static final int STATE_INVALID = 8;
+
+ /**
+ * The final state for a tool to be in. Once a tool reaches this state, it
+ * will not change states until it is activated() again.
+ */
+ protected static final int STATE_TERMINAL = 1 << 30;
+
+ /**
+ * Key modifier for ignoring snap while dragging. It's CTRL on Mac, and ALT
+ * on all other platforms.
+ */
+ protected static final int MODIFIER_NO_SNAPPING;
+
+ static {
+ if (Platform.OS_MACOSX.equals(Platform.getOS())) {
+ MODIFIER_NO_SNAPPING = SWT.CTRL;
+ } else {
+ MODIFIER_NO_SNAPPING = SWT.ALT;
+ }
+ }
+
+ private long accessibleBegin;
+
+ private int accessibleStep;
+ private Command command;
+
+ private CommandStackEventListener commandStackListener = new CommandStackEventListener() {
+ @Override
+ public void stackChanged(CommandStackEvent event) {
+ if (event.isPreChangeEvent()) {
+ handleCommandStackChanged();
+ }
+ }
+ };
+ private Input current;
+ private EditPartViewer currentViewer;
+ private Cursor defaultCursor, disabledCursor;
+ private EditDomain domain;
+ private List operationSet;
+ private int startX, startY, state;
+
+ boolean acceptAbort(KeyEvent e) {
+ return e.character == SWT.ESC;
+ }
+
+ /**
+ * Returns true if the event corresponds to an arrow key with the
+ * appropriate modifiers and if the system is in a state where the arrow key
+ * should be accepted.
+ *
+ * @param e
+ * the key event
+ * @return true if the arrow key should be accepted by this tool
+ * @since 3.4
+ */
+ protected boolean acceptArrowKey(KeyEvent e) {
+ int key = e.keyCode;
+ if (!(isInState(STATE_INITIAL | STATE_ACCESSIBLE_DRAG
+ | STATE_ACCESSIBLE_DRAG_IN_PROGRESS))) {
+ return false;
+ }
+ return (key == SWT.ARROW_UP) || (key == SWT.ARROW_RIGHT)
+ || (key == SWT.ARROW_DOWN) || (key == SWT.ARROW_LEFT);
+ }
+
+ boolean acceptDragCommit(KeyEvent e) {
+ return isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)
+ && e.character == 13;
+ }
+
+ int accGetStep() {
+ return accessibleStep;
+ }
+
+ void accStepIncrement() {
+ if (accessibleBegin == -1) {
+ accessibleBegin = new Date().getTime();
+ accessibleStep = 1;
+ } else {
+ accessibleStep = 4;
+ long elapsed = new Date().getTime() - accessibleBegin;
+ if (elapsed > 1000) {
+ accessibleStep = Math.min(16, (int) (elapsed / 150));
+ }
+ }
+ }
+
+ void accStepReset() {
+ accessibleBegin = -1;
+ }
+
+ /**
+ * Activates the tool. Any initialization should be performed here. This
+ * method is called when a tool is selected.
+ *
+ * @see #deactivate()
+ */
+ @Override
+ public void activate() {
+ resetFlags();
+ accessibleBegin = -1;
+ getCurrentInput().verifyMouseButtons = true;
+ setState(STATE_INITIAL);
+ setFlag(FLAG_ACTIVE, true);
+ getDomain().getCommandStack().addCommandStackEventListener(
+ commandStackListener);
+ }
+
+ /**
+ * Convenience method to add the given figure to the feedback layer.
+ *
+ * @param figure
+ * the feedback being added
+ */
+ protected void addFeedback(IFigure figure) {
+ LayerManager lm = (LayerManager) getCurrentViewer()
+ .getEditPartRegistry().get(LayerManager.ID);
+ if (lm == null) {
+ return;
+ }
+ lm.getLayer(LayerConstants.FEEDBACK_LAYER).add(figure);
+ }
+
+ /**
+ * This method is invoked from {@link #setProperties(Map)}. Sub-classes can
+ * override to add support for more properties. This method should fail
+ * silently in case of any error.
+ * <p>
+ * AbstractTool uses introspection to match any keys with properties. For instance, the key "defaultCursor" would lead to the invocation of {@link #setDefaultCursor(Cursor)} with the provided value.
+ *
+ * @param key
+ * the key; may be <code>null</code>
+ * @param value
+ * the new value
+ * @since 3.1
+ * @see #setProperties(Map)
+ */
+ protected void applyProperty(Object key, Object value) {
+ if (PROPERTY_UNLOAD_WHEN_FINISHED.equals(key)) {
+ if (value instanceof Boolean) {
+ setUnloadWhenFinished(((Boolean) value).booleanValue());
+ }
+ return;
+ }
+
+ if (!(key instanceof String)) {
+ return;
+ }
+
+ try {
+ PropertyDescriptor[] descriptors = Introspector.getBeanInfo(
+ getClass(), Introspector.IGNORE_ALL_BEANINFO)
+ .getPropertyDescriptors();
+ PropertyDescriptor property = null;
+ for (int i = 0; i < descriptors.length; i++) {
+ if (descriptors[i].getName().equals(key)) {
+ property = descriptors[i];
+ break;
+ }
+ }
+ if (property != null) {
+ Method setter = property.getWriteMethod();
+ // setter.setAccessible(true);
+ setter.invoke(this, new Object[] { value });
+ }
+ } catch (IntrospectionException ie) {
+ } catch (IllegalAccessException iae) {
+ } catch (InvocationTargetException ite) {
+ } catch (SecurityException se) {
+ }
+ }
+
+ /**
+ * Returns the appropriate cursor for the tools current state. If the tool
+ * is in its terminal state, <code>null</code> is returned. Otherwise,
+ * either the default or disabled cursor is returned, based on the existence
+ * of a current command, and whether that current command is executable.
+ * <P>
+ * Subclasses may override or extend this method to calculate the appropriate cursor based on other conditions.
+ *
+ * @see #getDefaultCursor()
+ * @see #getDisabledCursor()
+ * @see #getCurrentCommand()
+ * @return <code>null</code> or a cursor to be displayed.
+ */
+ protected Cursor calculateCursor() {
+ if (isInState(STATE_TERMINAL)) {
+ return null;
+ }
+ Command command = getCurrentCommand();
+ if (command == null || !command.canExecute()) {
+ return getDisabledCursor();
+ }
+ return getDefaultCursor();
+ }
+
+ /**
+ * Added for compatibility. {@link DragTracker#commitDrag()} was added for
+ * accessibility reasons. Since all tool implementations must inherit from
+ * this base class, then implementing this method here avoids breaking
+ * subclasses that implemented the {@link DragTracker} interface.
+ */
+ public void commitDrag() {
+ }
+
+ /**
+ * Returns a new List of editparts that this tool is operating on. This
+ * method is called once during {@link #getOperationSet()}, and its result
+ * is cached.
+ * <P>
+ * By default, the operations set is the current viewer's entire selection. Subclasses may override this method to filter or alter the operation set as necessary.
+ *
+ * @return a list of editparts being operated on
+ */
+ protected List createOperationSet() {
+ return new ArrayList(getCurrentViewer().getSelectedEditParts());
+ }
+
+ /**
+ * Deactivates the tool. This method is called whenever the user switches to
+ * another tool. Use this method to do some clean-up when the tool is
+ * switched. The abstract tool allows cursors for viewers to be changed.
+ * When the tool is deactivated it must revert to normal the cursor of the
+ * last tool it changed.
+ *
+ * @see #activate()
+ */
+ @Override
+ public void deactivate() {
+ setFlag(FLAG_ACTIVE, false);
+ setViewer(null);
+ setCurrentCommand(null);
+ setState(STATE_TERMINAL);
+ operationSet = null;
+ current = null;
+ getDomain().getCommandStack().removeCommandStackEventListener(
+ commandStackListener);
+ }
+
+ /**
+ * Prints a string in the GEF Debug console if the Tools debug option is
+ * selected.
+ *
+ * @param message
+ * a message for the debug trace tool
+ * @deprecated
+ */
+ @Deprecated
+ protected void debug(String message) {
+ }
+
+ /**
+ * Executes the given command on the command stack.
+ *
+ * @since 3.1
+ * @param command
+ * the command to execute
+ */
+ protected void executeCommand(Command command) {
+ getDomain().getCommandStack().removeCommandStackEventListener(
+ commandStackListener);
+ try {
+ getDomain().getCommandStack().execute(command);
+ } finally {
+ getDomain().getCommandStack().addCommandStackEventListener(
+ commandStackListener);
+ }
+ }
+
+ /**
+ * Execute the currently active command.
+ */
+ protected void executeCurrentCommand() {
+ Command curCommand = getCurrentCommand();
+ if (curCommand != null && curCommand.canExecute()) {
+ executeCommand(curCommand);
+ }
+ setCurrentCommand(null);
+ }
+
+ /**
+ * Called when a viewer that the editor controls gains focus.
+ *
+ * @param event
+ * The SWT focus event
+ * @param viewer
+ * The viewer that the focus event is over.
+ */
+ @Override
+ public void focusGained(FocusEvent event, EditPartViewer viewer) {
+ setViewer(viewer);
+ handleFocusGained();
+ }
+
+ /**
+ * Called when a viewer that the editor controls loses focus.
+ *
+ * @param event
+ * The SWT focus event
+ * @param viewer
+ * The viewer that the focus event is over.
+ */
+ @Override
+ public void focusLost(FocusEvent event, EditPartViewer viewer) {
+ setViewer(viewer);
+ handleFocusLost();
+ }
+
+ /**
+ * Returns a new, updated command based on the tool's current properties.
+ * The default implementation returns an unexecutable command. Some tools do
+ * not work commands and the model, but simply change the viewer's state in
+ * some way.
+ *
+ * @return a newly obtained command
+ */
+ protected Command getCommand() {
+ return org.eclipse.gef.commands.UnexecutableCommand.INSTANCE;
+ }
+
+ /**
+ * Returns the identifier of the command that is being sought. This name is
+ * also the named that will be logged in the debug view.
+ *
+ * @return the identifier for the command
+ */
+ protected abstract String getCommandName();
+
+ /**
+ * Returns the currently cached command.
+ *
+ * @return the current command
+ * @see #setCurrentCommand(Command)
+ */
+ protected Command getCurrentCommand() {
+ return command;
+ }
+
+ /**
+ * Returns the input object encapsulating the current mouse and keyboard
+ * state.
+ *
+ * @return the current input
+ */
+ protected Input getCurrentInput() {
+ if (current == null) {
+ current = new Input();
+ }
+ return current;
+ }
+
+ /**
+ * Return the viewer that the tool is currently receiving input from, or <code>null</code>. The last viewer to dispatch an event is defined as the
+ * current viewer. Current viewer is automatically updated as events are
+ * received, and is set to <code>null</code> on <code>deactivate()</code>.
+ *
+ * @return the current viewer
+ */
+ protected EditPartViewer getCurrentViewer() {
+ return currentViewer;
+ }
+
+ /**
+ * Returns the debug name for this tool.
+ *
+ * @return the debug name
+ */
+ protected String getDebugName() {
+ return getClass().getName();
+ }
+
+ /**
+ * Returns a String representation of the given state for debug purposes.
+ *
+ * @param state
+ * the state
+ * @return the string for the given state
+ */
+ protected String getDebugNameForState(int state) {
+ switch (state) {
+ case STATE_INITIAL:
+ return "Initial State";//$NON-NLS-1$
+ case STATE_DRAG:
+ return "Drag State";//$NON-NLS-1$
+ case STATE_DRAG_IN_PROGRESS:
+ return "Drag In Progress State";//$NON-NLS-1$
+ case STATE_INVALID:
+ return "Invalid State"; //$NON-NLS-1$
+ case STATE_TERMINAL:
+ return "Terminal State"; //$NON-NLS-1$
+ case STATE_ACCESSIBLE_DRAG:
+ return "Accessible Drag"; //$NON-NLS-1$
+ case STATE_ACCESSIBLE_DRAG_IN_PROGRESS:
+ return "Accessible Drag In Progress"; //$NON-NLS-1$
+ }
+ return "Unknown state:";//$NON-NLS-1$
+ }
+
+ /**
+ * Returns the cursor used under normal conditions.
+ *
+ * @see #setDefaultCursor(Cursor)
+ * @return the default cursor
+ */
+ protected Cursor getDefaultCursor() {
+ return defaultCursor;
+ }
+
+ /**
+ * Returns the cursor used under abnormal conditions.
+ *
+ * @see #calculateCursor()
+ * @see #setDisabledCursor(Cursor)
+ * @return the disabled cursor
+ */
+ protected Cursor getDisabledCursor() {
+ if (disabledCursor != null) {
+ return disabledCursor;
+ }
+ return getDefaultCursor();
+ }
+
+ /**
+ * Returns the EditDomain. A tool is told its EditDomain when it becomes
+ * active. A tool may need to know its edit domain prior to receiving any
+ * events from any of that domain's viewers.
+ *
+ * @return the editdomain
+ */
+ protected EditDomain getDomain() {
+ return domain;
+ }
+
+ /**
+ * Return the number of pixels that the mouse has been moved since that drag
+ * was started. The drag start is determined by where the mouse button was
+ * first pressed.
+ *
+ * @see #getStartLocation()
+ * @return the drag delta
+ */
+ protected Dimension getDragMoveDelta() {
+ return getLocation().getDifference(getStartLocation());
+ }
+
+ /**
+ * Returns the current x, y position of the mouse cursor.
+ *
+ * @return the mouse location
+ */
+ protected Point getLocation() {
+ return new Point(getCurrentInput().getMouseLocation());
+ }
+
+ /**
+ * Lazily creates and returns the list of editparts on which the tool
+ * operates. The list is initially <code>null</code>, in which case {@link #createOperationSet()} is called, and its results cached until the
+ * tool is deactivated.
+ *
+ * @return the operation set.
+ */
+ protected List getOperationSet() {
+ if (operationSet == null) {
+ operationSet = createOperationSet();
+ }
+ return operationSet;
+ }
+
+ /**
+ * Returns the starting mouse location for the current tool operation. This
+ * is typically the mouse location where the user first pressed a mouse
+ * button. This is important for tools that interpret mouse drags.
+ *
+ * @return the start location
+ */
+ protected Point getStartLocation() {
+ return new Point(startX, startY);
+ }
+
+ /**
+ * Returns the tool's current state.
+ *
+ * @return the current state
+ */
+ protected int getState() {
+ return state;
+ }
+
+ /**
+ * Called when the mouse button has been pressed. By default, nothing
+ * happens and <code>false</code> is returned. Subclasses may override this
+ * method to interpret the meaning of a mouse down. Returning <code>true</code> indicates that the button down was handled in some way.
+ *
+ * @param button
+ * which button went down
+ * @return <code>true</code> if the buttonDown was handled
+ */
+ protected boolean handleButtonDown(int button) {
+ return false;
+ }
+
+ /**
+ * Called when the mouse button has been released. By default, nothing
+ * happens and <code>false</code> is returned. Subclasses may override this
+ * method to interpret the mouse up. Returning <code>true</code> indicates
+ * that the mouse up was handled in some way.
+ *
+ * @see #mouseUp(MouseEvent, EditPartViewer)
+ * @param button
+ * the button being released
+ * @return <code>true</code> if the button up was handled
+ */
+ protected boolean handleButtonUp(int button) {
+ return false;
+ }
+
+ /**
+ * Called when the command stack has changed, for instance, when a delete or
+ * undo command has been executed. By default, state is set to <code>STATE_INVALID</code> and handleInvalidInput is called. Subclasses
+ * may override this method to change what happens when the command stack
+ * changes. Returning <code>true</code> indicates that the change was
+ * handled in some way.
+ *
+ * @return <code>true</code> if the change was handled in some way
+ */
+ protected boolean handleCommandStackChanged() {
+ if (!isInState(STATE_INITIAL | STATE_INVALID)) {
+ setState(STATE_INVALID);
+ handleInvalidInput();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Called when a mouse double-click occurs. By default, nothing happens and <code>false</code> is returned. Subclasses may override this method to
+ * interpret double-clicks. Returning <code>true</code> indicates that the
+ * event was handled in some way.
+ *
+ * @param button
+ * which button was double-clicked
+ * @return <code>true</code> if the event was handled
+ * @see #mouseDoubleClick(MouseEvent, EditPartViewer)
+ */
+ protected boolean handleDoubleClick(int button) {
+ return false;
+ }
+
+ /**
+ * Called whenever the mouse is being dragged. This method continues to be
+ * called even once {@link #handleDragInProgress()} starts getting called.
+ * By default, nothing happens, and <code>false</code> is returned.
+ * Subclasses may override this method to interpret a drag. Returning <code>true</code> indicates that the drag was handled in some way.
+ *
+ * @return <code>true</code> if the drag is handled
+ * @see #mouseDrag(MouseEvent, EditPartViewer)
+ */
+ protected boolean handleDrag() {
+ return false;
+ }
+
+ /**
+ * Called whenever a mouse is being dragged and the drag threshold has been
+ * exceeded. Prior to the drag threshold being exceeded, only {@link #handleDrag()} is called. This method gets called repeatedly for
+ * every mouse move during the drag. By default, nothing happens and <code>false</code> is returned. Subclasses may override this method to
+ * interpret the drag. Returning <code>true</code> indicates that the drag
+ * was handled.
+ *
+ * @see #movedPastThreshold()
+ * @see #mouseDrag(MouseEvent, EditPartViewer)
+ * @return <code>true</code> if the drag was handled
+ */
+ protected boolean handleDragInProgress() {
+ return false;
+ }
+
+ /**
+ * Called only one time during a drag when the drag threshold has been
+ * exceeded. By default, nothing happens and <code>false</code> is returned.
+ * Subclasses may override to interpret the drag starting. Returning <code>true</code> indicates that the event was handled.
+ *
+ * @see #movedPastThreshold()
+ * @see #mouseDrag(MouseEvent, EditPartViewer)
+ * @return true if the drag starting was handled
+ */
+ protected boolean handleDragStarted() {
+ return false;
+ }
+
+ /**
+ * Called when the current tool operation is to be completed. In other
+ * words, the "state machine" and has accepted the sequence of input (i.e.
+ * the mouse gesture). By default, the tool will either reactivate itself,
+ * or ask the edit domain to load the default tool.
+ * <P>
+ * Subclasses should extend this method to first do whatever it is that the tool does, and then call <code>super</code>.
+ *
+ * @see #unloadWhenFinished()
+ */
+ protected void handleFinished() {
+ if (unloadWhenFinished()) {
+ getDomain().loadDefaultTool();
+ } else {
+ reactivate();
+ }
+ }
+
+ /**
+ * Handles high-level processing of a focus gained event. By default,
+ * nothing happens and <code>false</code> is returned. Subclasses may
+ * override this method to interpret the focus gained event. Return <code>true</code> to indicate that the event was processed.
+ *
+ * @see #focusGained(FocusEvent, EditPartViewer)
+ * @return <code>true</code> if the event was handled
+ */
+ protected boolean handleFocusGained() {
+ return false;
+ }
+
+ /**
+ * Handles high-level processing of a focus lost event. By default, nothing
+ * happens and <code>false</code> is returned. Subclasses may override this
+ * method to interpret the focus lost event. Return <code>true</code> to
+ * indicate that the event was processed.
+ *
+ * @see #focusLost(FocusEvent, EditPartViewer)
+ * @return <code>true</code> if the event was handled
+ */
+ protected boolean handleFocusLost() {
+ return false;
+ }
+
+ /**
+ * Handles high-level processing of a mouse hover event. By default, nothing
+ * happens and <code>false</code> is returned. Subclasses may override this
+ * method to interpret the hover. Return <code>true</code> to indicate that
+ * the hover was handled.
+ *
+ * @see #mouseHover(MouseEvent, EditPartViewer)
+ * @return <code>true</code> if the hover was handled
+ */
+ protected boolean handleHover() {
+ return false;
+ }
+
+ /**
+ * Called when invalid input is encountered. The state does not change, so
+ * the caller must set the state to {@link AbstractTool#STATE_INVALID}.
+ *
+ * @return <code>true</code>
+ */
+ protected boolean handleInvalidInput() {
+ return false;
+ }
+
+ /**
+ * Handles high-level processing of a key down event. By default, the
+ * KeyEvent is checked to see if it is the ESCAPE key. If so, the domain's
+ * default tool is reloaded, and <code>true</code> is returned. Subclasses
+ * may extend this method to interpret additional key down events. Returns <code>true</code> if the given key down was handled.
+ *
+ * @see #keyDown(KeyEvent, EditPartViewer)
+ * @param e
+ * the key event
+ * @return <code>true</code> if the key down was handled.
+ */
+ protected boolean handleKeyDown(KeyEvent e) {
+ if (acceptAbort(e)) {
+ getDomain().loadDefaultTool();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Override to process a traverse event. If the event's {@link KeyEvent#doit doit} field is set to <code>false</code>, the
+ * traversal will be prevented from occurring. Otherwise, a traverse will
+ * occur.
+ *
+ * @param event
+ * the SWT traverse event
+ * @since 3.1
+ */
+ protected void handleKeyTraversed(TraverseEvent event) {
+ }
+
+ /**
+ * Handles high-level processing of a key up event. By default, does nothing
+ * and returns <code>false</code>. Subclasses may extend this method to
+ * process key up events. Returns <code>true</code> if the key up was
+ * processed in some way.
+ *
+ * @see #keyUp(KeyEvent, EditPartViewer)
+ * @param e
+ * the key event
+ * @return <code>true</code> if the event was handled
+ */
+ protected boolean handleKeyUp(KeyEvent e) {
+ return false;
+ }
+
+ /**
+ * Handles high-level processing of a mouse move. By default, does nothing
+ * and returns <code>false</code>. Subclasses may extend this method to
+ * process mouse moves. Returns <code>true</code> if the mouse move was
+ * processed.
+ *
+ * @see #mouseMove(MouseEvent, EditPartViewer)
+ * @return <code>true</code> if the mouse move was handled
+ */
+ protected boolean handleMove() {
+ return false;
+ }
+
+ /**
+ * Handles when a native drag has ended. By default, does nothing and
+ * returns <code>false</code>. Subclasses may extend this method to process
+ * native drags ending.
+ *
+ * @param event
+ * the drag event
+ * @return <code>true</code> if the native drag finished was handled
+ */
+ protected boolean handleNativeDragFinished(DragSourceEvent event) {
+ return false;
+ }
+
+ /**
+ * Handles when a native drag has started. By default, does nothing and
+ * returns <code>false</code>. Subclasses may extend this method to process
+ * native drag starts.
+ * <P>
+ * When a native drag starts, all subsequent mouse events will not be received, including the mouseUp event. The only event that will be received is the drag finished event.
+ *
+ * @param event
+ * the drag event
+ * @return <code>true</code> if the native drag start was handled
+ */
+ protected boolean handleNativeDragStarted(DragSourceEvent event) {
+ return false;
+ }
+
+ /**
+ * Called when the mouse enters an EditPartViewer. By default, does nothing
+ * and returns <code>false</code>. Subclasses may extend this method to
+ * process the viewer enter. Returns <code>true</code> to indicate if the
+ * viewer entered was process in some way.
+ *
+ * @return <code>true</code> if the viewer entered was handled
+ */
+ protected boolean handleViewerEntered() {
+ return false;
+ }
+
+ /**
+ * Called when the mouse exits an EditPartViewer. By default, does nothing
+ * and returns <code>false</code>. Subclasses may extend this method to
+ * process viewer exits. Returns <code>true</code> to indicate if the viewer
+ * exited was process in some way.
+ *
+ * @return <code>true</code> if the viewer exited was handled
+ */
+ protected boolean handleViewerExited() {
+ return false;
+ }
+
+ /**
+ * Returns <code>true</code> if the tool is active.
+ *
+ * @return <code>true</code> if active
+ */
+ protected boolean isActive() {
+ return getFlag(FLAG_ACTIVE);
+ }
+
+ private boolean isCurrentViewerMirrored() {
+ return (getCurrentViewer().getControl().getStyle() & SWT.MIRRORED) != 0;
+ }
+
+ /**
+ * Returns <code>true</code> if the tool is hovering.
+ *
+ * @return <code>true</code> if hovering
+ */
+ protected boolean isHoverActive() {
+ return getFlag(FLAG_HOVER);
+ }
+
+ boolean isInDragInProgress() {
+ return isInState(STATE_DRAG_IN_PROGRESS
+ | STATE_ACCESSIBLE_DRAG_IN_PROGRESS);
+ }
+
+ /*
+ * Returns <code>true</code> if the current {@link Input} is synchronized
+ * with the current MouseEvent.
+ */
+ private boolean isInputSynched(MouseEvent event) {
+ Input input = getCurrentInput();
+ return input.isMouseButtonDown(1) == ((event.stateMask & SWT.BUTTON1) != 0)
+ && input.isMouseButtonDown(2) == ((event.stateMask & SWT.BUTTON2) != 0)
+ && input.isMouseButtonDown(3) == ((event.stateMask & SWT.BUTTON3) != 0)
+ && input.isMouseButtonDown(4) == ((event.stateMask & SWT.BUTTON4) != 0)
+ && input.isMouseButtonDown(5) == ((event.stateMask & SWT.BUTTON5) != 0);
+ }
+
+ /**
+ * Returns <code>true</code> if the tool is in the given state.
+ *
+ * @param state
+ * the state being queried
+ * @return <code>true</code> if the tool is in the given state
+ */
+ protected boolean isInState(int state) {
+ return ((getState() & state) != 0);
+ }
+
+ /**
+ * Default implementation always returns <code>true</code>. Sub-classes may
+ * override.
+ *
+ * @param viewer
+ * the viewer where the event occured
+ * @return <code>true</code> if this tool is interested in events occuring
+ * in the given viewer; <code>false</code> otherwise
+ * @since 3.1
+ */
+ protected boolean isViewerImportant(EditPartViewer viewer) {
+ return true;
+ }
+
+ /**
+ * Receives a KeyDown event for the given viewer. Subclasses wanting to
+ * handle this event should override {@link #handleKeyDown(KeyEvent)}.
+ *
+ * @param evt
+ * the key event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void keyDown(KeyEvent evt, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ getCurrentInput().setInput(evt);
+ handleKeyDown(evt);
+ }
+
+ /**
+ * Receives a traversal event for the given viewer. Subclasses wanting to
+ * handle this event should override {@link #handleKeyTraversed(TraverseEvent)}.
+ *
+ * @param event
+ * the traverse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void keyTraversed(TraverseEvent event, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ getCurrentInput().setInput(event);
+ handleKeyTraversed(event);
+ }
+
+ /**
+ * Receives a KeyUp event for the given viewer. Subclasses wanting to handle
+ * this event should override {@link #handleKeyUp(KeyEvent)}.
+ *
+ * @param evt
+ * the key event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void keyUp(KeyEvent evt, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ getCurrentInput().setInput(evt);
+ handleKeyUp(evt);
+ }
+
+ /**
+ * Handles mouse double click events within a viewer. Subclasses wanting to
+ * handle this event should override {@link #handleDoubleClick(int)}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void mouseDoubleClick(MouseEvent me, EditPartViewer viewer) {
+ if (me.button > 5 || !isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ getCurrentInput().setInput(me);
+
+ handleDoubleClick(me.button);
+ }
+
+ /**
+ * Handles mouse down events within a viewer. Subclasses wanting to handle
+ * this event should override {@link #handleButtonDown(int)}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void mouseDown(MouseEvent me, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+
+ getCurrentInput().setInput(me);
+ getCurrentInput().setMouseButton(me.button, true);
+
+ setStartLocation(new Point(me.x, me.y));
+
+ handleButtonDown(me.button);
+ }
+
+ /**
+ * Handles mouse drag events within a viewer. Subclasses wanting to handle
+ * this event should override {@link #handleDrag()} and/or {@link #handleDragInProgress()}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void mouseDrag(MouseEvent me, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ boolean wasDragging = movedPastThreshold();
+ getCurrentInput().setInput(me);
+ handleDrag();
+ if (movedPastThreshold()) {
+ if (!wasDragging) {
+ handleDragStarted();
+ }
+ handleDragInProgress();
+ }
+ }
+
+ /**
+ * Handles mouse hover event. within a viewer. Subclasses wanting to handle
+ * this event should override {@link #handleHover()}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ *
+ */
+ @Override
+ public void mouseHover(MouseEvent me, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ getCurrentInput().setInput(me);
+ handleHover();
+ }
+
+ /**
+ * Handles mouse moves (if the mouse button is up) within a viewer.
+ * Subclasses wanting to handle this event should override {@link #handleMove()}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void mouseMove(MouseEvent me, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ if (!isInputSynched(me)) {
+ boolean b1 = getCurrentInput().isMouseButtonDown(1);
+ boolean b2 = getCurrentInput().isMouseButtonDown(2);
+ boolean b3 = getCurrentInput().isMouseButtonDown(3);
+ boolean b4 = getCurrentInput().isMouseButtonDown(4);
+ boolean b5 = getCurrentInput().isMouseButtonDown(5);
+ getCurrentInput().verifyMouseButtons = true;
+ getCurrentInput().setInput(me);
+ if (b1) {
+ handleButtonUp(1);
+ }
+ if (b2) {
+ handleButtonUp(2);
+ }
+ if (b3) {
+ handleButtonUp(3);
+ }
+ if (b4) {
+ handleButtonUp(4);
+ }
+ if (b5) {
+ handleButtonUp(5);
+ }
+ if (getDomain().getActiveTool() != this) {
+ return;
+ }
+ /*
+ * processing one of the buttonUps may have caused the tool to
+ * reactivate itself, which causes the viewer to get nulled-out. If
+ * we are going to call another handleXxx method below, we must set
+ * the viewer again to be paranoid.
+ */
+ setViewer(viewer);
+ } else {
+ getCurrentInput().setInput(me);
+ }
+ if (isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
+ handleDragInProgress();
+ } else {
+ handleMove();
+ }
+ }
+
+ /**
+ * Handles mouse up within a viewer. Subclasses wanting to handle this event
+ * should override {@link #handleButtonUp(int)}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void mouseUp(MouseEvent me, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ getCurrentInput().setInput(me);
+ getCurrentInput().setMouseButton(me.button, false);
+ handleButtonUp(me.button);
+ }
+
+ /**
+ * Handles mouse-wheel scrolling for a viewer. Sub-classes may override as
+ * needed. The default implementation delegates to {@link #performViewerMouseWheel(Event, EditPartViewer)} IFF the tool is
+ * in the initial state. Mouse-wheel events generated at other times are
+ * ignored.
+ *
+ * @param event
+ * the SWT scroll event
+ * @param viewer
+ * the originating viewer
+ * @see #performViewerMouseWheel(Event, EditPartViewer)
+ */
+ @Override
+ public void mouseWheelScrolled(Event event, EditPartViewer viewer) {
+ if (isInState(STATE_INITIAL)) {
+ performViewerMouseWheel(event, viewer);
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if the threshold has been exceeded during a
+ * mouse drag.
+ *
+ * @return <code>true</code> if the threshold has been exceeded
+ */
+ protected boolean movedPastThreshold() {
+ if (getFlag(FLAG_PAST_THRESHOLD)) {
+ return true;
+ }
+ Point start = getStartLocation(), end = getLocation();
+ if (Math.abs(start.x - end.x) > DRAG_THRESHOLD
+ || Math.abs(start.y - end.y) > DRAG_THRESHOLD) {
+ setFlag(FLAG_PAST_THRESHOLD, true);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @see org.eclipse.gef.Tool#nativeDragFinished(DragSourceEvent, EditPartViewer)
+ */
+ @Override
+ public void nativeDragFinished(DragSourceEvent event, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ handleNativeDragFinished(event);
+ }
+
+ /**
+ * @see org.eclipse.gef.Tool#nativeDragStarted(DragSourceEvent, EditPartViewer)
+ */
+ @Override
+ public void nativeDragStarted(DragSourceEvent event, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ setViewer(viewer);
+ handleNativeDragStarted(event);
+ }
+
+ /**
+ * Delegates mouse-wheel event handling to registered {@link MouseWheelHandler MouseWheelHandlers} based on the given Event's
+ * statemask. Does nothing if there are no matching handlers found.
+ *
+ * @param event
+ * the SWT scroll event
+ * @param viewer
+ * the originating viewer
+ * @since 3.1
+ */
+ protected void performViewerMouseWheel(Event event, EditPartViewer viewer) {
+ MouseWheelHandler handler = (MouseWheelHandler) viewer
+ .getProperty(MouseWheelHandler.KeyGenerator
+ .getKey(event.stateMask));
+ if (handler != null) {
+ handler.handleMouseWheel(event, viewer);
+ }
+ }
+
+ /**
+ * Places the mouse in the viewer based on the point given. If the point
+ * given is outside the viewer, then the mouse is placed in the location
+ * nearest the given point but within the viewer.
+ *
+ * @param p
+ * the point
+ * @since 3.4
+ */
+ protected void placeMouseInViewer(Point p) {
+ if (getCurrentViewer() == null) {
+ return;
+ }
+ Control c = getCurrentViewer().getControl();
+ Rectangle rect;
+ if (c instanceof Scrollable) {
+ rect = ((Scrollable) c).getClientArea();
+ } else {
+ rect = c.getBounds();
+ }
+ if (p.x > rect.x + rect.width - 1) {
+ p.x = rect.x + rect.width - 1;
+ } else if (p.x < rect.x) {
+ p.x = rect.x;
+ }
+ if (p.y > rect.y + rect.height - 1) {
+ p.y = rect.y + rect.height - 1;
+ } else if (p.y < rect.y) {
+ p.y = rect.y;
+ }
+
+ // place the mouse cursor at the calculated position within the viewer
+ org.eclipse.swt.graphics.Point cursorLocation = new org.eclipse.swt.graphics.Point(
+ p.x, p.y);
+ cursorLocation = c.toDisplay(cursorLocation);
+ // calling Display#setCursorLocation(Point) will cause an SWT.MouseMove
+ // event to be dispatched as a result, so that mouseMove(MouseEvent,
+ // EditPartViewer) will be triggered as a result, which will react to
+ // the movement by delegating to handleMove() or handleDragInProgress().
+ c.getDisplay().setCursorLocation(cursorLocation);
+ }
+
+ /**
+ * Calls <code>deactivate()</code> and then <code>activate()</code>.
+ */
+ protected void reactivate() {
+ // Fix for Bug# 91448
+ EditPartViewer viewer = getCurrentViewer();
+ deactivate();
+ activate();
+ if (viewer != null) {
+ Control c = viewer.getControl();
+ if (c != null && !c.isDisposed() && c.isFocusControl()) {
+ setViewer(viewer);
+ }
+ }
+ }
+
+ /**
+ * Sets the cursor being displayed to the appropriate cursor. If the tool is
+ * active, the current cursor being displayed is updated by calling {@link #calculateCursor()}.
+ */
+ protected void refreshCursor() {
+ if (isActive()) {
+ setCursor(calculateCursor());
+ }
+ }
+
+ /**
+ * Releases tool capture.
+ *
+ * @see #setToolCapture()
+ */
+ protected void releaseToolCapture() {
+ getCurrentViewer().setRouteEventsToEditDomain(false);
+ }
+
+ /**
+ * Convenience method to removes a figure from the feedback layer.
+ *
+ * @param figure
+ * the figure being removed
+ */
+ protected void removeFeedback(IFigure figure) {
+ LayerManager lm = (LayerManager) getCurrentViewer()
+ .getEditPartRegistry().get(LayerManager.ID);
+ if (lm == null) {
+ return;
+ }
+ lm.getLayer(LayerConstants.FEEDBACK_LAYER).remove(figure);
+ }
+
+ /**
+ * Resets all stateful flags to their initial values. Subclasses should
+ * extend this method to reset their own custom flags.
+ */
+ protected void resetFlags() {
+ setFlag(FLAG_PAST_THRESHOLD, false);
+ setFlag(FLAG_HOVER, false);
+ }
+
+ /**
+ * Used to cache a command obtained from {@link #getCommand()}.
+ *
+ * @param c
+ * the command
+ * @see #getCurrentCommand()
+ */
+ protected void setCurrentCommand(Command c) {
+ command = c;
+ refreshCursor();
+ }
+
+ /**
+ * Shows the given cursor on the current viewer.
+ *
+ * @param cursor
+ * the cursor to display
+ */
+ protected void setCursor(Cursor cursor) {
+ if (getCurrentViewer() != null) {
+ getCurrentViewer().setCursor(cursor);
+ }
+ }
+
+ /**
+ * Sets the default cursor.
+ *
+ * @param cursor
+ * the cursor
+ * @see #getDefaultCursor()
+ */
+ public void setDefaultCursor(Cursor cursor) {
+ if (defaultCursor == cursor) {
+ return;
+ }
+ defaultCursor = cursor;
+ refreshCursor();
+ }
+
+ /**
+ * Sets the disabled cursor.
+ *
+ * @param cursor
+ * the cursor
+ * @see #getDisabledCursor()
+ */
+ public void setDisabledCursor(Cursor cursor) {
+ if (disabledCursor == cursor) {
+ return;
+ }
+ disabledCursor = cursor;
+ refreshCursor();
+ }
+
+ /**
+ * Sets the EditDomain.
+ *
+ * @param domain
+ * the edit domain
+ * @see #getDomain()
+ */
+ @Override
+ public void setEditDomain(EditDomain domain) {
+ this.domain = domain;
+ }
+
+ /**
+ * Sets whether the hover flag is true or false. Subclasses which do
+ * something on hover can use this flag to track whether they have received
+ * a hover or not.
+ *
+ * @param value
+ * whether hover is active
+ */
+ protected void setHoverActive(boolean value) {
+ setFlag(FLAG_HOVER, value);
+ }
+
+ void setMouseCapture(boolean value) {
+ if (getCurrentViewer() != null
+ && getCurrentViewer().getControl() != null
+ && !getCurrentViewer().getControl().isDisposed()) {
+ getCurrentViewer().getControl().setCapture(value);
+ }
+ }
+
+ /**
+ * An example is {@link #PROPERTY_UNLOAD_WHEN_FINISHED} -> Boolean.
+ * AbstractTool uses introspection to set properties that are not explicitly
+ * specified. For instance, the key "defaultCursor" will cause {@link #setDefaultCursor(Cursor)} to be invoked with the given value.
+ *
+ * @see org.eclipse.gef.Tool#setProperties(java.util.Map)
+ */
+ @Override
+ public void setProperties(Map properties) {
+ if (properties == null) {
+ return;
+ }
+ Iterator entries = properties.entrySet().iterator();
+ while (entries.hasNext()) {
+ Entry entry = (Entry) entries.next();
+ applyProperty(entry.getKey(), entry.getValue());
+ }
+ }
+
+ /**
+ * Sets the start mouse location, typically for a drag operation.
+ *
+ * @param p
+ * the start location
+ */
+ protected void setStartLocation(Point p) {
+ startX = p.x;
+ startY = p.y;
+ }
+
+ /**
+ * Sets the tools state.
+ *
+ * @param state
+ * the new state
+ */
+ protected void setState(int state) {
+ this.state = state;
+ }
+
+ /**
+ * Sets tool capture. When a tool has capture, viewers will make every
+ * effort to send events through the editdomain to the tool. Therefore, the
+ * default handling of some events is bypassed.
+ */
+ protected void setToolCapture() {
+ getCurrentViewer().setRouteEventsToEditDomain(true);
+ }
+
+ /**
+ * Setting this to <code>true</code> will cause the tool to be unloaded
+ * after one operation has completed. The default value is <code>true</code> . The tool is unloaded, and the edit domains default tool will be
+ * activated.
+ *
+ * @param value
+ * whether the tool should be unloaded on completion
+ */
+ public void setUnloadWhenFinished(boolean value) {
+ setFlag(FLAG_UNLOAD, value);
+ }
+
+ /**
+ * Sets the active EditPartViewer. The active viewer is the viewer from
+ * which the last event was received.
+ *
+ * @param viewer
+ * the viewer
+ */
+ @Override
+ public void setViewer(EditPartViewer viewer) {
+ if (viewer == currentViewer) {
+ return;
+ }
+
+ setCursor(null);
+ currentViewer = viewer;
+ if (currentViewer != null) {
+ org.eclipse.swt.graphics.Point p = currentViewer.getControl()
+ .toControl(Display.getCurrent().getCursorLocation());
+ getCurrentInput().setMouseLocation(p.x, p.y);
+ }
+ refreshCursor();
+ }
+
+ /**
+ * Returns <code>true</code> if the give state transition succeeds. This is
+ * a "test and set" operation, where the tool is tested to be in the
+ * specified start state, and if so, is set to the given end state. The
+ * method returns the result of the first test.
+ *
+ * @param start
+ * the start state being tested
+ * @param end
+ * the end state
+ * @return <code>true</code> if the state transition is successful
+ */
+ protected boolean stateTransition(int start, int end) {
+ if ((getState() & start) != 0) {
+ setState(end);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns <code>true</code> if the tool is set to unload when its current
+ * operation is complete.
+ *
+ * @return <code>true</code> if the tool should be unloaded when finished
+ */
+ protected final boolean unloadWhenFinished() {
+ return getFlag(FLAG_UNLOAD);
+ }
+
+ /**
+ * Receives the mouse entered event. Subclasses wanting to handle this event
+ * should override {@link #handleViewerEntered()}.
+ * <p>
+ * FEATURE in SWT: mouseExit comes after mouseEntered on the new control. Therefore, if the current viewer is not <code>null</code>, it means the exit has not been sent yet by SWT. To maintain proper ordering, GEF fakes the exit and calls
+ * {@link #handleViewerExited()}. The real exit will then be ignored.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void viewerEntered(MouseEvent me, EditPartViewer viewer) {
+ if (!isViewerImportant(viewer)) {
+ return;
+ }
+ getCurrentInput().setInput(me);
+ if (getCurrentViewer() != null && getCurrentViewer() != viewer) {
+ handleViewerExited();
+ }
+ setViewer(viewer);
+ handleViewerEntered();
+ }
+
+ /**
+ * Handles the mouse exited event. Subclasses wanting to handle this event
+ * should override {@link #handleViewerExited()}.
+ *
+ * @param me
+ * the mouse event
+ * @param viewer
+ * the originating viewer
+ */
+ @Override
+ public void viewerExited(MouseEvent me, EditPartViewer viewer) {
+ /*
+ * FEATURE in SWT. mouseExited comes after mouseEntered. So only call
+ * handle exit if we didn't previously fake it on viewer entered.
+ */
+ if (viewer == getCurrentViewer()) {
+ getCurrentInput().setInput(me);
+ handleViewerExited();
+ setViewer(null);
+ }
+ }
+
+ /**
+ * Allows the user to access mouse and keyboard input.
+ */
+ public static class Input extends org.eclipse.gef.util.FlagSupport {
+ int modifiers;
+ Point mouse = new Point();
+ boolean verifyMouseButtons;
+
+ /**
+ * Returns the event modifiers. Modifiers are defined in {@link MouseEvent#stateMask}, and include things like the mouse
+ * buttons and keyboard modifier keys.
+ *
+ * @return the event modifiers
+ */
+ protected int getModifiers() {
+ return modifiers;
+ }
+
+ /**
+ * Returns the current location of the mouse.
+ *
+ * @return the mouse location
+ */
+ public Point getMouseLocation() {
+ return mouse;
+ }
+
+ /**
+ * Returns <code>true</code> if the ALT key is pressed.
+ *
+ * @return <code>true</code> if the ALT key is pressed
+ */
+ public boolean isAltKeyDown() {
+ return (modifiers & SWT.ALT) != 0;
+ }
+
+ /**
+ * Returns <code>true</code> if any of the mouse buttons are pressed.
+ *
+ * @return <code>true</code> if any of the mouse buttons are pressed
+ */
+ public boolean isAnyButtonDown() {
+ return getFlag(2 | 4 | 8 | 16 | 32);
+ }
+
+ /**
+ * Returns <code>true</code> if the CTRL key is pressed.
+ *
+ * @return <code>true</code> of CTRL pressed
+ */
+ public boolean isControlKeyDown() {
+ return (modifiers & SWT.CONTROL) != 0;
+ }
+
+ /**
+ * Returns <code>true</code> if any of the given mod keys are pressed.
+ *
+ * @param mod
+ * SWT.MOD1, SWT.MOD2, SWT.MOD3, SWT.MOD4 or any combination
+ * thereof
+ * @return <code>true</code> if the given mod key is pressed
+ * @since 3.1
+ */
+ public boolean isModKeyDown(int mod) {
+ return (modifiers & mod) != 0;
+ }
+
+ /**
+ * Returns <code>true</code> if the specified button is down.
+ *
+ * @param which
+ * which button
+ * @return <code>true</code> if the button is down
+ */
+ public boolean isMouseButtonDown(int which) {
+ return getFlag(1 << which);
+ }
+
+ /**
+ * Returns <code>true</code> if the SHIFT key is pressed.
+ *
+ * @return <code>true</code> if SHIFT pressed
+ */
+ public boolean isShiftKeyDown() {
+ return (modifiers & SWT.SHIFT) != 0;
+ }
+
+ /**
+ * Sets the keyboard input based on the KeyEvent.
+ *
+ * @param ke
+ * the key event providing the input
+ */
+ public void setInput(KeyEvent ke) {
+ modifiers = ke.stateMask;
+ }
+
+ /**
+ * Sets the mouse and keyboard input based on the MouseEvent.
+ *
+ * @param me
+ * the mouse event providing the input
+ */
+ public void setInput(MouseEvent me) {
+ setMouseLocation(me.x, me.y);
+ modifiers = me.stateMask;
+ if (verifyMouseButtons) {
+ setMouseButton(1, (modifiers & SWT.BUTTON1) != 0);
+ setMouseButton(2, (modifiers & SWT.BUTTON2) != 0);
+ setMouseButton(3, (modifiers & SWT.BUTTON3) != 0);
+ setMouseButton(4, (modifiers & SWT.BUTTON4) != 0);
+ setMouseButton(5, (modifiers & SWT.BUTTON5) != 0);
+ verifyMouseButtons = false;
+ }
+ }
+
+ /**
+ * Sets mouse button # <code>which</code> to be pressed if <code>state</code> is true.
+ *
+ * @param which
+ * which button
+ * @param state
+ * <code>true</code> if button down
+ */
+ public void setMouseButton(int which, boolean state) {
+ setFlag(1 << which, state);
+ }
+
+ /**
+ * Sets the current location of the mouse
+ *
+ * @param x
+ * x location
+ * @param y
+ * y location
+ * @since 3.4
+ */
+ public void setMouseLocation(int x, int y) {
+ mouse.setLocation(x, y);
+ }
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/CustomDragEditPartsTracker.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/CustomDragEditPartsTracker.java
index 9749da1625b..7b2a80e4075 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/CustomDragEditPartsTracker.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/CustomDragEditPartsTracker.java
@@ -1,720 +1,720 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 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
- * Adapted Code from gef.tools.DragEditPartTracker by Vicnent Lorenzo CEA-LIST, some method have been added as the end of this class
- *******************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.snap.copy;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.draw2d.Cursors;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.PrecisionPoint;
-import org.eclipse.draw2d.geometry.PrecisionRectangle;
-import org.eclipse.gef.AutoexposeHelper;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gef.LayerConstants;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.SharedCursors;
-import org.eclipse.gef.SnapToHelper;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gef.editparts.LayerManager;
-import org.eclipse.gef.handles.HandleBounds;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.tools.ToolUtilities;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.graphics.Cursor;
-
-/**
- * A DragTracker that moves {@link org.eclipse.gef.EditPart EditParts}.
- */
-public class CustomDragEditPartsTracker extends SelectEditPartTracker {
-
- /**
- * Key modifier for cloning. It's ALT on Mac, and CTRL on all other
- * platforms.
- */
- static final int MODIFIER_CLONE;
-
- static {
- if (Platform.OS_MACOSX.equals(Platform.getOS())) {
- MODIFIER_CLONE = SWT.ALT;
- } else {
- MODIFIER_CLONE = SWT.CTRL;
- }
- }
-
- /**
- * Key modifier for constrained move. It's SHIFT on all platforms.
- */
- static final int MODIFIER_CONSTRAINED_MOVE = SWT.SHIFT;
-
- private static final int FLAG_SOURCE_FEEDBACK = SelectEditPartTracker.MAX_FLAG << 1;
-
- /** Max flag */
- protected static final int MAX_FLAG = FLAG_SOURCE_FEEDBACK;
-
- private List exclusionSet;
-
- private PrecisionPoint sourceRelativeStartPoint;
-
- private SnapToHelper snapToHelper;
-
- private PrecisionRectangle sourceRectangle, compoundSrcRect;
-
- private boolean cloneActive;
-
- /**
- * Constructs a new DragEditPartsTracker with the given source edit part.
- *
- * @param sourceEditPart
- * the source edit part
- */
- public CustomDragEditPartsTracker(EditPart sourceEditPart) {
- super(sourceEditPart);
-
- cloneActive = false;
- setDisabledCursor(Cursors.NO);
- }
-
- /**
- * Returns true if the control key was the key in the key event and the tool
- * is in an acceptable state for this event.
- *
- * @param e
- * the key event
- * @return true if the key was control and can be accepted.
- */
- private boolean acceptClone(KeyEvent e) {
- int key = e.keyCode;
- if (!(isInState(STATE_DRAG_IN_PROGRESS | STATE_ACCESSIBLE_DRAG | STATE_ACCESSIBLE_DRAG_IN_PROGRESS))) {
- return false;
- }
- return (key == MODIFIER_CLONE);
- }
-
- private boolean acceptSHIFT(KeyEvent e) {
- return isInState(STATE_DRAG_IN_PROGRESS | STATE_ACCESSIBLE_DRAG | STATE_ACCESSIBLE_DRAG_IN_PROGRESS) && e.keyCode == SWT.SHIFT;
- }
-
- /**
- * Returns the cursor used under normal conditions.
- *
- * @see #setDefaultCursor(Cursor)
- * @return the default cursor
- */
- @Override
- protected Cursor getDefaultCursor() {
- if (isCloneActive()) {
- return SharedCursors.CURSOR_TREE_ADD;
- }
- return super.getDefaultCursor();
- }
-
- /**
- * Erases feedback and calls {@link #performDrag()}. Sets the state to
- * terminal.
- *
- * @see org.eclipse.gef.tools.AbstractTool#commitDrag()
- */
- @Override
- public void commitDrag() {
- eraseSourceFeedback();
- eraseTargetFeedback();
- performDrag();
- setState(STATE_TERMINAL);
- }
-
- /**
- * Captures the bounds of the source being dragged, and the unioned bounds
- * of all figures being dragged. These bounds are used for snapping by the
- * snap strategies in <code>updateTargetRequest()</code>.
- */
- private void captureSourceDimensions() {
- List editparts = getOperationSet();
- for (int i = 0; i < editparts.size(); i++) {
- GraphicalEditPart child = (GraphicalEditPart) editparts.get(i);
- IFigure figure = child.getFigure();
- PrecisionRectangle bounds = null;
- if (figure instanceof HandleBounds) {
- bounds = new PrecisionRectangle(((HandleBounds) figure).getHandleBounds());
- } else {
- bounds = new PrecisionRectangle(figure.getBounds());
- }
- figure.translateToAbsolute(bounds);
-
- if (compoundSrcRect == null) {
- compoundSrcRect = new PrecisionRectangle(bounds);
- } else {
- compoundSrcRect = compoundSrcRect.union(bounds);
- }
- if (child == getSourceEditPart()) {
- sourceRectangle = bounds;
- }
- }
- if (sourceRectangle == null) {
- IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
- if (figure instanceof HandleBounds) {
- sourceRectangle = new PrecisionRectangle(((HandleBounds) figure).getHandleBounds());
- } else {
- sourceRectangle = new PrecisionRectangle(figure.getBounds());
- }
- figure.translateToAbsolute(sourceRectangle);
- }
- }
-
- /**
- * Returns a List of top-level edit parts excluding dependants (by calling {@link ToolUtilities#getSelectionWithoutDependants(EditPartViewer)} that
- * understand the current target request (by calling {@link ToolUtilities#filterEditPartsUnderstanding(List, Request)}.
- *
- * @see org.eclipse.gef.tools.AbstractTool#createOperationSet()
- */
- @Override
- protected List createOperationSet() {
- if (getCurrentViewer() != null) {
- List list = ToolUtilities.getSelectionWithoutDependants(getCurrentViewer());
- ToolUtilities.filterEditPartsUnderstanding(list, getTargetRequest());
- return list;
- }
-
- return new ArrayList();
- }
-
- /**
- * Creates a {@link ChangeBoundsRequest}. By default, the type is {@link RequestConstants#REQ_MOVE}. Later on when the edit parts are asked
- * to contribute to the overall command, the request type will be either {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN},
- * depending on the result of {@link #isMove()}.
- *
- * @see org.eclipse.gef.tools.TargetingTool#createTargetRequest()
- */
- @Override
- protected Request createTargetRequest() {
- if (isCloneActive()) {
- return new ChangeBoundsRequest(REQ_CLONE);
- } else {
- return new ChangeBoundsRequest(REQ_MOVE);
- }
- }
-
- /**
- * Erases source feedback and sets the autoexpose helper to <code>null</code>.
- *
- * @see org.eclipse.gef.Tool#deactivate()
- */
- @Override
- public void deactivate() {
- eraseSourceFeedback();
- super.deactivate();
- exclusionSet = null;
- sourceRelativeStartPoint = null;
- sourceRectangle = null;
- compoundSrcRect = null;
- snapToHelper = null;
- }
-
- /**
- * Asks the edit parts in the {@link AbstractTool#getOperationSet()
- * operation set} to erase their source feedback.
- */
- protected void eraseSourceFeedback() {
- if (!getFlag(FLAG_SOURCE_FEEDBACK)) {
- return;
- }
- setFlag(FLAG_SOURCE_FEEDBACK, false);
- List editParts = getOperationSet();
- for (int i = 0; i < editParts.size(); i++) {
- EditPart editPart = (EditPart) editParts.get(i);
- editPart.eraseSourceFeedback(getTargetRequest());
- }
- }
-
- /**
- * Asks each edit part in the {@link AbstractTool#getOperationSet()
- * operation set} to contribute to a {@link CompoundCommand} after first
- * setting the request type to either {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN}, depending on the result of {@link #isMove()}.
- *
- * @see org.eclipse.gef.tools.AbstractTool#getCommand()
- */
- @Override
- protected Command getCommand() {
- CompoundCommand command = new CompoundCommand();
- command.setDebugLabel("Drag Object Tracker");//$NON-NLS-1$
-
- Iterator iter = getOperationSet().iterator();
-
- Request request = getTargetRequest();
-
- if (isCloneActive()) {
- request.setType(REQ_CLONE);
- } else if (isMove()) {
- request.setType(REQ_MOVE);
- } else {
- request.setType(REQ_ORPHAN);
- }
-
- if (!isCloneActive()) {
- while (iter.hasNext()) {
- EditPart editPart = (EditPart) iter.next();
- command.add(editPart.getCommand(request));
- }
- }
-
- if (!isMove() || isCloneActive()) {
- if (!isCloneActive()) {
- request.setType(REQ_ADD);
- }
-
- if (getTargetEditPart() == null) {
- command.add(UnexecutableCommand.INSTANCE);
- } else {
- command.add(getTargetEditPart().getCommand(getTargetRequest()));
- }
- }
-
- return command.unwrap();
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
- */
- @Override
- protected String getCommandName() {
- if (isCloneActive()) {
- return REQ_CLONE;
- } else if (isMove()) {
- return REQ_MOVE;
- } else {
- return REQ_ADD;
- }
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
- */
- @Override
- protected String getDebugName() {
- return "DragEditPartsTracker:" + getCommandName();//$NON-NLS-1$
- }
-
- /**
- * Returns a list of all the edit parts in the {@link AbstractTool#getOperationSet() operation set}, plus the {@link org.eclipse.draw2d.ConnectionLayer}.
- *
- * @see org.eclipse.gef.tools.TargetingTool#getExclusionSet()
- */
- @Override
- protected Collection getExclusionSet() {
- if (exclusionSet == null) {
- List set = getOperationSet();
- exclusionSet = new ArrayList(set.size() + 1);
- for (int i = 0; i < set.size(); i++) {
- GraphicalEditPart editpart = (GraphicalEditPart) set.get(i);
- exclusionSet.add(editpart.getFigure());
- }
- LayerManager layerManager = (LayerManager) getCurrentViewer().getEditPartRegistry().get(LayerManager.ID);
- if (layerManager != null) {
- exclusionSet.add(layerManager.getLayer(LayerConstants.CONNECTION_LAYER));
- }
- }
- return exclusionSet;
- }
-
- /**
- * @see org.eclipse.gef.tools.TargetingTool#handleAutoexpose()
- */
- @Override
- protected void handleAutoexpose() {
- updateTargetRequest();
- updateTargetUnderMouse();
- showTargetFeedback();
- showSourceFeedback();
- setCurrentCommand(getCommand());
- }
-
- /**
- * Erases feedback and calls {@link #performDrag()}.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
- */
- @Override
- protected boolean handleButtonUp(int button) {
- if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
- eraseSourceFeedback();
- eraseTargetFeedback();
- performDrag();
- return true;
- }
- return super.handleButtonUp(button);
- }
-
- /**
- * Updates the target request and mouse target, asks to show feedback, and
- * sets the current command.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleDragInProgress()
- */
- @Override
- protected boolean handleDragInProgress() {
- if (isInDragInProgress()) {
- updateTargetRequest();
- if (updateTargetUnderMouse()) {
- updateTargetRequest();
- }
- showTargetFeedback();
- showSourceFeedback();
- setCurrentCommand(getCommand());
- }
- return true;
- }
-
- /**
- * Calls {@link TargetingTool#updateAutoexposeHelper()} if a drag is in
- * progress.
- *
- * @see org.eclipse.gef.tools.TargetingTool#handleHover()
- */
- @Override
- protected boolean handleHover() {
- if (isInDragInProgress()) {
- updateAutoexposeHelper();
- }
- return true;
- }
-
- /**
- * Erases source feedback.
- *
- * @see org.eclipse.gef.tools.TargetingTool#handleInvalidInput()
- */
- @Override
- protected boolean handleInvalidInput() {
- super.handleInvalidInput();
- eraseSourceFeedback();
- return true;
- }
-
- /**
- * Processes arrow keys used to move edit parts.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleKeyDown(org.eclipse.swt.events.KeyEvent)
- */
- @Override
- protected boolean handleKeyDown(KeyEvent e) {
- setAutoexposeHelper(null);
- if (acceptArrowKey(e)) {
- accStepIncrement();
- if (stateTransition(STATE_INITIAL, STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
- setStartLocation(getLocation());
- }
- switch (e.keyCode) {
- case SWT.ARROW_DOWN:
- placeMouseInViewer(getLocation().getTranslated(0, accGetStep()));
- break;
- case SWT.ARROW_UP:
- placeMouseInViewer(getLocation().getTranslated(0, -accGetStep()));
- break;
- case SWT.ARROW_RIGHT:
- int stepping = accGetStep();
- if (isCurrentViewerMirrored()) {
- stepping = -stepping;
- }
- placeMouseInViewer(getLocation().getTranslated(stepping, 0));
- break;
- case SWT.ARROW_LEFT:
- int step = -accGetStep();
- if (isCurrentViewerMirrored()) {
- step = -step;
- }
- placeMouseInViewer(getLocation().getTranslated(step, 0));
- break;
- }
- return true;
- } else if (acceptClone(e)) {
- setCloneActive(true);
- handleDragInProgress();
- return true;
- } else if (acceptSHIFT(e)) {
- handleDragInProgress();
- return true;
- }
-
- return false;
- }
-
- private boolean isCurrentViewerMirrored() {
- return (getCurrentViewer().getControl().getStyle() & SWT.MIRRORED) != 0;
- }
-
- /**
- * Interprets and processes clone deactivation, constrained move
- * deactivation, and accessibility navigation reset.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleKeyUp(org.eclipse.swt.events.KeyEvent)
- */
- @Override
- protected boolean handleKeyUp(KeyEvent e) {
- if (acceptArrowKey(e)) {
- accStepReset();
- return true;
- } else if (acceptClone(e)) {
- setCloneActive(false);
- handleDragInProgress();
- return true;
- } else if (acceptSHIFT(e)) {
- handleDragInProgress();
- return true;
- }
- return false;
- }
-
- /**
- * Returns true if the current drag is a clone operation.
- *
- * @return true if cloning is enabled and is currently active.
- */
- protected boolean isCloneActive() {
- return cloneActive;
- }
-
- /**
- * Returns <code>true</code> if the source edit part is being moved within
- * its parent. If the source edit part is being moved to another parent,
- * this returns <code>false</code>.
- *
- * @return <code>true</code> if the source edit part is not being reparented
- */
- protected boolean isMove() {
- EditPart part = getSourceEditPart();
- while (part != getTargetEditPart() && part != null) {
- if (part.getParent() == getTargetEditPart() && part.getSelected() != EditPart.SELECTED_NONE) {
- return true;
- }
- part = part.getParent();
- }
- return false;
- }
-
- /**
- * Calls {@link AbstractTool#executeCurrentCommand()}.
- */
- protected void performDrag() {
- executeCurrentCommand();
- }
-
- /**
- * If auto scroll (also called auto expose) is being performed, the start
- * location moves during the scroll. This method updates that location.
- */
- protected void repairStartLocation() {
- if (sourceRelativeStartPoint == null) {
- return;
- }
- IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
- PrecisionPoint newStart = (PrecisionPoint) sourceRelativeStartPoint.getCopy();
- figure.translateToAbsolute(newStart);
- Point delta = new Point(newStart.x - getStartLocation().x, newStart.y - getStartLocation().y);
- setStartLocation(newStart);
- // sourceRectangle and compoundSrcRect need to be updated as well when
- // auto-scrolling
- if (sourceRectangle != null) {
- sourceRectangle.translate(delta);
- }
- if (compoundSrcRect != null) {
- compoundSrcRect.translate(delta);
- }
- }
-
- /**
- * @see org.eclipse.gef.tools.TargetingTool#setAutoexposeHelper(org.eclipse.gef.AutoexposeHelper)
- */
- @Override
- protected void setAutoexposeHelper(AutoexposeHelper helper) {
- super.setAutoexposeHelper(helper);
- if (helper != null && sourceRelativeStartPoint == null && isInDragInProgress()) {
- IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
- sourceRelativeStartPoint = new PrecisionPoint(getStartLocation());
- figure.translateToRelative(sourceRelativeStartPoint);
- }
- }
-
- /**
- * Enables cloning if the value is true.
- *
- * @param cloneActive
- * <code>true</code> if cloning should be active
- */
- protected void setCloneActive(boolean cloneActive) {
- if (this.cloneActive == cloneActive) {
- return;
- }
- eraseSourceFeedback();
- eraseTargetFeedback();
- this.cloneActive = cloneActive;
- }
-
- /**
- * Extended to update the current snap-to strategy.
- *
- * @see org.eclipse.gef.tools.TargetingTool#setTargetEditPart(org.eclipse.gef.EditPart)
- */
- @Override
- protected void setTargetEditPart(EditPart editpart) {
- if (getTargetEditPart() == editpart) {
- return;
- }
- super.setTargetEditPart(editpart);
- snapToHelper = null;
- if (getTargetEditPart() != null && getOperationSet().size() > 0) {
- snapToHelper = (SnapToHelper) getTargetEditPart().getAdapter(SnapToHelper.class);
- }
- }
-
- /**
- * Asks the edit parts in the {@link AbstractTool#getOperationSet()
- * operation set} to show source feedback.
- */
- protected void showSourceFeedback() {
- List editParts = getOperationSet();
- for (int i = 0; i < editParts.size(); i++) {
- EditPart editPart = (EditPart) editParts.get(i);
- editPart.showSourceFeedback(getTargetRequest());
- }
- setFlag(FLAG_SOURCE_FEEDBACK, true);
- }
-
- /**
- * Extended to activate cloning and to update the captured source dimensions
- * when applicable.
- *
- * @see org.eclipse.gef.tools.AbstractTool#setState(int)
- */
- @Override
- protected void setState(int state) {
- boolean check = isInState(STATE_INITIAL);
- super.setState(state);
-
- if (isInState(STATE_ACCESSIBLE_DRAG | STATE_DRAG_IN_PROGRESS | STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
- if (getCurrentInput().isModKeyDown(MODIFIER_CLONE)) {
- setCloneActive(true);
- handleDragInProgress();
- }
- }
-
- if (check && isInState(STATE_DRAG | STATE_ACCESSIBLE_DRAG | STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
- captureSourceDimensions();
- }
- }
-
- /**
- * Calls {@link #repairStartLocation()} in case auto scroll is being
- * performed. Updates the request with the current {@link AbstractTool#getOperationSet() operation set}, move delta,
- * location and type.
- *
- * @see org.eclipse.gef.tools.TargetingTool#updateTargetRequest()
- */
- @Override
- protected void updateTargetRequest() {
- repairStartLocation();
- ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
- request.setEditParts(getOperationSet());
- Dimension delta = getDragMoveDelta();
-
- request.setConstrainedMove(getCurrentInput().isModKeyDown(MODIFIER_CONSTRAINED_MOVE));
- request.setSnapToEnabled(!getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING));
-
- // constrains the move to dx=0, dy=0, or dx=dy if shift is depressed
- if (request.isConstrainedMove()) {
- float ratio = 0;
-
- if (delta.width != 0) {
- ratio = (float) delta.height / (float) delta.width;
- }
-
- ratio = Math.abs(ratio);
- if (ratio > 0.5 && ratio < 1.5) {
- if (Math.abs(delta.height) > Math.abs(delta.width)) {
- if (delta.height > 0) {
- delta.height = Math.abs(delta.width);
- } else {
- delta.height = -Math.abs(delta.width);
- }
- } else {
- if (delta.width > 0) {
- delta.width = Math.abs(delta.height);
- } else {
- delta.width = -Math.abs(delta.height);
- }
- }
- } else {
- if (Math.abs(delta.width) > Math.abs(delta.height)) {
- delta.height = 0;
- } else {
- delta.width = 0;
- }
- }
- }
-
- Point moveDelta = new Point(delta.width, delta.height);
- request.getExtendedData().clear();
- request.setMoveDelta(moveDelta);
- snapPoint(request);
-
- request.setLocation(getLocation());
- request.setType(getCommandName());
- }
-
- /**
- * This method can be overridden by clients to customize the snapping
- * behavior.
- *
- * @param request
- * the <code>ChangeBoundsRequest</code> from which the move delta
- * can be extracted and updated
- * @since 3.4
- */
- protected void snapPoint(ChangeBoundsRequest request) {
- Point moveDelta = request.getMoveDelta();
- if (snapToHelper != null && request.isSnapToEnabled()) {
- PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
- PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy();
- baseRect.translate(moveDelta);
- jointRect.translate(moveDelta);
-
- PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
- snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRect, jointRect }, preciseDelta);
- request.setMoveDelta(preciseDelta);
- }
- }
-
-
- // -----------------------------added methods for Papyrus
- protected PrecisionRectangle getSourceRectangle() {
- return this.sourceRectangle.getPreciseCopy();
- }
-
- protected SnapToHelper getSnapToHelper() {
- return this.snapToHelper;
- }
-
- protected PrecisionRectangle getCompoundSourceRectangle() {
- return this.compoundSrcRect.getPreciseCopy();
- }
-}
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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
+ * Adapted Code from gef.tools.DragEditPartTracker by Vicnent Lorenzo CEA-LIST, some method have been added as the end of this class
+ *******************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.snap.copy;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.draw2d.Cursors;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.PrecisionPoint;
+import org.eclipse.draw2d.geometry.PrecisionRectangle;
+import org.eclipse.gef.AutoexposeHelper;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gef.LayerConstants;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.SharedCursors;
+import org.eclipse.gef.SnapToHelper;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.editparts.LayerManager;
+import org.eclipse.gef.handles.HandleBounds;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.tools.ToolUtilities;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Cursor;
+
+/**
+ * A DragTracker that moves {@link org.eclipse.gef.EditPart EditParts}.
+ */
+public class CustomDragEditPartsTracker extends SelectEditPartTracker {
+
+ /**
+ * Key modifier for cloning. It's ALT on Mac, and CTRL on all other
+ * platforms.
+ */
+ static final int MODIFIER_CLONE;
+
+ static {
+ if (Platform.OS_MACOSX.equals(Platform.getOS())) {
+ MODIFIER_CLONE = SWT.ALT;
+ } else {
+ MODIFIER_CLONE = SWT.CTRL;
+ }
+ }
+
+ /**
+ * Key modifier for constrained move. It's SHIFT on all platforms.
+ */
+ static final int MODIFIER_CONSTRAINED_MOVE = SWT.SHIFT;
+
+ private static final int FLAG_SOURCE_FEEDBACK = SelectEditPartTracker.MAX_FLAG << 1;
+
+ /** Max flag */
+ protected static final int MAX_FLAG = FLAG_SOURCE_FEEDBACK;
+
+ private List exclusionSet;
+
+ private PrecisionPoint sourceRelativeStartPoint;
+
+ private SnapToHelper snapToHelper;
+
+ private PrecisionRectangle sourceRectangle, compoundSrcRect;
+
+ private boolean cloneActive;
+
+ /**
+ * Constructs a new DragEditPartsTracker with the given source edit part.
+ *
+ * @param sourceEditPart
+ * the source edit part
+ */
+ public CustomDragEditPartsTracker(EditPart sourceEditPart) {
+ super(sourceEditPart);
+
+ cloneActive = false;
+ setDisabledCursor(Cursors.NO);
+ }
+
+ /**
+ * Returns true if the control key was the key in the key event and the tool
+ * is in an acceptable state for this event.
+ *
+ * @param e
+ * the key event
+ * @return true if the key was control and can be accepted.
+ */
+ private boolean acceptClone(KeyEvent e) {
+ int key = e.keyCode;
+ if (!(isInState(STATE_DRAG_IN_PROGRESS | STATE_ACCESSIBLE_DRAG | STATE_ACCESSIBLE_DRAG_IN_PROGRESS))) {
+ return false;
+ }
+ return (key == MODIFIER_CLONE);
+ }
+
+ private boolean acceptSHIFT(KeyEvent e) {
+ return isInState(STATE_DRAG_IN_PROGRESS | STATE_ACCESSIBLE_DRAG | STATE_ACCESSIBLE_DRAG_IN_PROGRESS) && e.keyCode == SWT.SHIFT;
+ }
+
+ /**
+ * Returns the cursor used under normal conditions.
+ *
+ * @see #setDefaultCursor(Cursor)
+ * @return the default cursor
+ */
+ @Override
+ protected Cursor getDefaultCursor() {
+ if (isCloneActive()) {
+ return SharedCursors.CURSOR_TREE_ADD;
+ }
+ return super.getDefaultCursor();
+ }
+
+ /**
+ * Erases feedback and calls {@link #performDrag()}. Sets the state to
+ * terminal.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#commitDrag()
+ */
+ @Override
+ public void commitDrag() {
+ eraseSourceFeedback();
+ eraseTargetFeedback();
+ performDrag();
+ setState(STATE_TERMINAL);
+ }
+
+ /**
+ * Captures the bounds of the source being dragged, and the unioned bounds
+ * of all figures being dragged. These bounds are used for snapping by the
+ * snap strategies in <code>updateTargetRequest()</code>.
+ */
+ private void captureSourceDimensions() {
+ List editparts = getOperationSet();
+ for (int i = 0; i < editparts.size(); i++) {
+ GraphicalEditPart child = (GraphicalEditPart) editparts.get(i);
+ IFigure figure = child.getFigure();
+ PrecisionRectangle bounds = null;
+ if (figure instanceof HandleBounds) {
+ bounds = new PrecisionRectangle(((HandleBounds) figure).getHandleBounds());
+ } else {
+ bounds = new PrecisionRectangle(figure.getBounds());
+ }
+ figure.translateToAbsolute(bounds);
+
+ if (compoundSrcRect == null) {
+ compoundSrcRect = new PrecisionRectangle(bounds);
+ } else {
+ compoundSrcRect = compoundSrcRect.union(bounds);
+ }
+ if (child == getSourceEditPart()) {
+ sourceRectangle = bounds;
+ }
+ }
+ if (sourceRectangle == null) {
+ IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
+ if (figure instanceof HandleBounds) {
+ sourceRectangle = new PrecisionRectangle(((HandleBounds) figure).getHandleBounds());
+ } else {
+ sourceRectangle = new PrecisionRectangle(figure.getBounds());
+ }
+ figure.translateToAbsolute(sourceRectangle);
+ }
+ }
+
+ /**
+ * Returns a List of top-level edit parts excluding dependants (by calling {@link ToolUtilities#getSelectionWithoutDependants(EditPartViewer)} that
+ * understand the current target request (by calling {@link ToolUtilities#filterEditPartsUnderstanding(List, Request)}.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#createOperationSet()
+ */
+ @Override
+ protected List createOperationSet() {
+ if (getCurrentViewer() != null) {
+ List list = ToolUtilities.getSelectionWithoutDependants(getCurrentViewer());
+ ToolUtilities.filterEditPartsUnderstanding(list, getTargetRequest());
+ return list;
+ }
+
+ return new ArrayList();
+ }
+
+ /**
+ * Creates a {@link ChangeBoundsRequest}. By default, the type is {@link RequestConstants#REQ_MOVE}. Later on when the edit parts are asked
+ * to contribute to the overall command, the request type will be either {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN},
+ * depending on the result of {@link #isMove()}.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#createTargetRequest()
+ */
+ @Override
+ protected Request createTargetRequest() {
+ if (isCloneActive()) {
+ return new ChangeBoundsRequest(REQ_CLONE);
+ } else {
+ return new ChangeBoundsRequest(REQ_MOVE);
+ }
+ }
+
+ /**
+ * Erases source feedback and sets the autoexpose helper to <code>null</code>.
+ *
+ * @see org.eclipse.gef.Tool#deactivate()
+ */
+ @Override
+ public void deactivate() {
+ eraseSourceFeedback();
+ super.deactivate();
+ exclusionSet = null;
+ sourceRelativeStartPoint = null;
+ sourceRectangle = null;
+ compoundSrcRect = null;
+ snapToHelper = null;
+ }
+
+ /**
+ * Asks the edit parts in the {@link AbstractTool#getOperationSet()
+ * operation set} to erase their source feedback.
+ */
+ protected void eraseSourceFeedback() {
+ if (!getFlag(FLAG_SOURCE_FEEDBACK)) {
+ return;
+ }
+ setFlag(FLAG_SOURCE_FEEDBACK, false);
+ List editParts = getOperationSet();
+ for (int i = 0; i < editParts.size(); i++) {
+ EditPart editPart = (EditPart) editParts.get(i);
+ editPart.eraseSourceFeedback(getTargetRequest());
+ }
+ }
+
+ /**
+ * Asks each edit part in the {@link AbstractTool#getOperationSet()
+ * operation set} to contribute to a {@link CompoundCommand} after first
+ * setting the request type to either {@link RequestConstants#REQ_MOVE} or {@link RequestConstants#REQ_ORPHAN}, depending on the result of {@link #isMove()}.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#getCommand()
+ */
+ @Override
+ protected Command getCommand() {
+ CompoundCommand command = new CompoundCommand();
+ command.setDebugLabel("Drag Object Tracker");//$NON-NLS-1$
+
+ Iterator iter = getOperationSet().iterator();
+
+ Request request = getTargetRequest();
+
+ if (isCloneActive()) {
+ request.setType(REQ_CLONE);
+ } else if (isMove()) {
+ request.setType(REQ_MOVE);
+ } else {
+ request.setType(REQ_ORPHAN);
+ }
+
+ if (!isCloneActive()) {
+ while (iter.hasNext()) {
+ EditPart editPart = (EditPart) iter.next();
+ command.add(editPart.getCommand(request));
+ }
+ }
+
+ if (!isMove() || isCloneActive()) {
+ if (!isCloneActive()) {
+ request.setType(REQ_ADD);
+ }
+
+ if (getTargetEditPart() == null) {
+ command.add(UnexecutableCommand.INSTANCE);
+ } else {
+ command.add(getTargetEditPart().getCommand(getTargetRequest()));
+ }
+ }
+
+ return command.unwrap();
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
+ */
+ @Override
+ protected String getCommandName() {
+ if (isCloneActive()) {
+ return REQ_CLONE;
+ } else if (isMove()) {
+ return REQ_MOVE;
+ } else {
+ return REQ_ADD;
+ }
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
+ */
+ @Override
+ protected String getDebugName() {
+ return "DragEditPartsTracker:" + getCommandName();//$NON-NLS-1$
+ }
+
+ /**
+ * Returns a list of all the edit parts in the {@link AbstractTool#getOperationSet() operation set}, plus the {@link org.eclipse.draw2d.ConnectionLayer}.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#getExclusionSet()
+ */
+ @Override
+ protected Collection getExclusionSet() {
+ if (exclusionSet == null) {
+ List set = getOperationSet();
+ exclusionSet = new ArrayList(set.size() + 1);
+ for (int i = 0; i < set.size(); i++) {
+ GraphicalEditPart editpart = (GraphicalEditPart) set.get(i);
+ exclusionSet.add(editpart.getFigure());
+ }
+ LayerManager layerManager = (LayerManager) getCurrentViewer().getEditPartRegistry().get(LayerManager.ID);
+ if (layerManager != null) {
+ exclusionSet.add(layerManager.getLayer(LayerConstants.CONNECTION_LAYER));
+ }
+ }
+ return exclusionSet;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.TargetingTool#handleAutoexpose()
+ */
+ @Override
+ protected void handleAutoexpose() {
+ updateTargetRequest();
+ updateTargetUnderMouse();
+ showTargetFeedback();
+ showSourceFeedback();
+ setCurrentCommand(getCommand());
+ }
+
+ /**
+ * Erases feedback and calls {@link #performDrag()}.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
+ */
+ @Override
+ protected boolean handleButtonUp(int button) {
+ if (stateTransition(STATE_DRAG_IN_PROGRESS, STATE_TERMINAL)) {
+ eraseSourceFeedback();
+ eraseTargetFeedback();
+ performDrag();
+ return true;
+ }
+ return super.handleButtonUp(button);
+ }
+
+ /**
+ * Updates the target request and mouse target, asks to show feedback, and
+ * sets the current command.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleDragInProgress()
+ */
+ @Override
+ protected boolean handleDragInProgress() {
+ if (isInDragInProgress()) {
+ updateTargetRequest();
+ if (updateTargetUnderMouse()) {
+ updateTargetRequest();
+ }
+ showTargetFeedback();
+ showSourceFeedback();
+ setCurrentCommand(getCommand());
+ }
+ return true;
+ }
+
+ /**
+ * Calls {@link TargetingTool#updateAutoexposeHelper()} if a drag is in
+ * progress.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#handleHover()
+ */
+ @Override
+ protected boolean handleHover() {
+ if (isInDragInProgress()) {
+ updateAutoexposeHelper();
+ }
+ return true;
+ }
+
+ /**
+ * Erases source feedback.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#handleInvalidInput()
+ */
+ @Override
+ protected boolean handleInvalidInput() {
+ super.handleInvalidInput();
+ eraseSourceFeedback();
+ return true;
+ }
+
+ /**
+ * Processes arrow keys used to move edit parts.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleKeyDown(org.eclipse.swt.events.KeyEvent)
+ */
+ @Override
+ protected boolean handleKeyDown(KeyEvent e) {
+ setAutoexposeHelper(null);
+ if (acceptArrowKey(e)) {
+ accStepIncrement();
+ if (stateTransition(STATE_INITIAL, STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
+ setStartLocation(getLocation());
+ }
+ switch (e.keyCode) {
+ case SWT.ARROW_DOWN:
+ placeMouseInViewer(getLocation().getTranslated(0, accGetStep()));
+ break;
+ case SWT.ARROW_UP:
+ placeMouseInViewer(getLocation().getTranslated(0, -accGetStep()));
+ break;
+ case SWT.ARROW_RIGHT:
+ int stepping = accGetStep();
+ if (isCurrentViewerMirrored()) {
+ stepping = -stepping;
+ }
+ placeMouseInViewer(getLocation().getTranslated(stepping, 0));
+ break;
+ case SWT.ARROW_LEFT:
+ int step = -accGetStep();
+ if (isCurrentViewerMirrored()) {
+ step = -step;
+ }
+ placeMouseInViewer(getLocation().getTranslated(step, 0));
+ break;
+ }
+ return true;
+ } else if (acceptClone(e)) {
+ setCloneActive(true);
+ handleDragInProgress();
+ return true;
+ } else if (acceptSHIFT(e)) {
+ handleDragInProgress();
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isCurrentViewerMirrored() {
+ return (getCurrentViewer().getControl().getStyle() & SWT.MIRRORED) != 0;
+ }
+
+ /**
+ * Interprets and processes clone deactivation, constrained move
+ * deactivation, and accessibility navigation reset.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleKeyUp(org.eclipse.swt.events.KeyEvent)
+ */
+ @Override
+ protected boolean handleKeyUp(KeyEvent e) {
+ if (acceptArrowKey(e)) {
+ accStepReset();
+ return true;
+ } else if (acceptClone(e)) {
+ setCloneActive(false);
+ handleDragInProgress();
+ return true;
+ } else if (acceptSHIFT(e)) {
+ handleDragInProgress();
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Returns true if the current drag is a clone operation.
+ *
+ * @return true if cloning is enabled and is currently active.
+ */
+ protected boolean isCloneActive() {
+ return cloneActive;
+ }
+
+ /**
+ * Returns <code>true</code> if the source edit part is being moved within
+ * its parent. If the source edit part is being moved to another parent,
+ * this returns <code>false</code>.
+ *
+ * @return <code>true</code> if the source edit part is not being reparented
+ */
+ protected boolean isMove() {
+ EditPart part = getSourceEditPart();
+ while (part != getTargetEditPart() && part != null) {
+ if (part.getParent() == getTargetEditPart() && part.getSelected() != EditPart.SELECTED_NONE) {
+ return true;
+ }
+ part = part.getParent();
+ }
+ return false;
+ }
+
+ /**
+ * Calls {@link AbstractTool#executeCurrentCommand()}.
+ */
+ protected void performDrag() {
+ executeCurrentCommand();
+ }
+
+ /**
+ * If auto scroll (also called auto expose) is being performed, the start
+ * location moves during the scroll. This method updates that location.
+ */
+ protected void repairStartLocation() {
+ if (sourceRelativeStartPoint == null) {
+ return;
+ }
+ IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
+ PrecisionPoint newStart = (PrecisionPoint) sourceRelativeStartPoint.getCopy();
+ figure.translateToAbsolute(newStart);
+ Point delta = new Point(newStart.x - getStartLocation().x, newStart.y - getStartLocation().y);
+ setStartLocation(newStart);
+ // sourceRectangle and compoundSrcRect need to be updated as well when
+ // auto-scrolling
+ if (sourceRectangle != null) {
+ sourceRectangle.translate(delta);
+ }
+ if (compoundSrcRect != null) {
+ compoundSrcRect.translate(delta);
+ }
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.TargetingTool#setAutoexposeHelper(org.eclipse.gef.AutoexposeHelper)
+ */
+ @Override
+ protected void setAutoexposeHelper(AutoexposeHelper helper) {
+ super.setAutoexposeHelper(helper);
+ if (helper != null && sourceRelativeStartPoint == null && isInDragInProgress()) {
+ IFigure figure = ((GraphicalEditPart) getSourceEditPart()).getFigure();
+ sourceRelativeStartPoint = new PrecisionPoint(getStartLocation());
+ figure.translateToRelative(sourceRelativeStartPoint);
+ }
+ }
+
+ /**
+ * Enables cloning if the value is true.
+ *
+ * @param cloneActive
+ * <code>true</code> if cloning should be active
+ */
+ protected void setCloneActive(boolean cloneActive) {
+ if (this.cloneActive == cloneActive) {
+ return;
+ }
+ eraseSourceFeedback();
+ eraseTargetFeedback();
+ this.cloneActive = cloneActive;
+ }
+
+ /**
+ * Extended to update the current snap-to strategy.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#setTargetEditPart(org.eclipse.gef.EditPart)
+ */
+ @Override
+ protected void setTargetEditPart(EditPart editpart) {
+ if (getTargetEditPart() == editpart) {
+ return;
+ }
+ super.setTargetEditPart(editpart);
+ snapToHelper = null;
+ if (getTargetEditPart() != null && getOperationSet().size() > 0) {
+ snapToHelper = (SnapToHelper) getTargetEditPart().getAdapter(SnapToHelper.class);
+ }
+ }
+
+ /**
+ * Asks the edit parts in the {@link AbstractTool#getOperationSet()
+ * operation set} to show source feedback.
+ */
+ protected void showSourceFeedback() {
+ List editParts = getOperationSet();
+ for (int i = 0; i < editParts.size(); i++) {
+ EditPart editPart = (EditPart) editParts.get(i);
+ editPart.showSourceFeedback(getTargetRequest());
+ }
+ setFlag(FLAG_SOURCE_FEEDBACK, true);
+ }
+
+ /**
+ * Extended to activate cloning and to update the captured source dimensions
+ * when applicable.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#setState(int)
+ */
+ @Override
+ protected void setState(int state) {
+ boolean check = isInState(STATE_INITIAL);
+ super.setState(state);
+
+ if (isInState(STATE_ACCESSIBLE_DRAG | STATE_DRAG_IN_PROGRESS | STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
+ if (getCurrentInput().isModKeyDown(MODIFIER_CLONE)) {
+ setCloneActive(true);
+ handleDragInProgress();
+ }
+ }
+
+ if (check && isInState(STATE_DRAG | STATE_ACCESSIBLE_DRAG | STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
+ captureSourceDimensions();
+ }
+ }
+
+ /**
+ * Calls {@link #repairStartLocation()} in case auto scroll is being
+ * performed. Updates the request with the current {@link AbstractTool#getOperationSet() operation set}, move delta,
+ * location and type.
+ *
+ * @see org.eclipse.gef.tools.TargetingTool#updateTargetRequest()
+ */
+ @Override
+ protected void updateTargetRequest() {
+ repairStartLocation();
+ ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
+ request.setEditParts(getOperationSet());
+ Dimension delta = getDragMoveDelta();
+
+ request.setConstrainedMove(getCurrentInput().isModKeyDown(MODIFIER_CONSTRAINED_MOVE));
+ request.setSnapToEnabled(!getCurrentInput().isModKeyDown(MODIFIER_NO_SNAPPING));
+
+ // constrains the move to dx=0, dy=0, or dx=dy if shift is depressed
+ if (request.isConstrainedMove()) {
+ float ratio = 0;
+
+ if (delta.width != 0) {
+ ratio = (float) delta.height / (float) delta.width;
+ }
+
+ ratio = Math.abs(ratio);
+ if (ratio > 0.5 && ratio < 1.5) {
+ if (Math.abs(delta.height) > Math.abs(delta.width)) {
+ if (delta.height > 0) {
+ delta.height = Math.abs(delta.width);
+ } else {
+ delta.height = -Math.abs(delta.width);
+ }
+ } else {
+ if (delta.width > 0) {
+ delta.width = Math.abs(delta.height);
+ } else {
+ delta.width = -Math.abs(delta.height);
+ }
+ }
+ } else {
+ if (Math.abs(delta.width) > Math.abs(delta.height)) {
+ delta.height = 0;
+ } else {
+ delta.width = 0;
+ }
+ }
+ }
+
+ Point moveDelta = new Point(delta.width, delta.height);
+ request.getExtendedData().clear();
+ request.setMoveDelta(moveDelta);
+ snapPoint(request);
+
+ request.setLocation(getLocation());
+ request.setType(getCommandName());
+ }
+
+ /**
+ * This method can be overridden by clients to customize the snapping
+ * behavior.
+ *
+ * @param request
+ * the <code>ChangeBoundsRequest</code> from which the move delta
+ * can be extracted and updated
+ * @since 3.4
+ */
+ protected void snapPoint(ChangeBoundsRequest request) {
+ Point moveDelta = request.getMoveDelta();
+ if (snapToHelper != null && request.isSnapToEnabled()) {
+ PrecisionRectangle baseRect = sourceRectangle.getPreciseCopy();
+ PrecisionRectangle jointRect = compoundSrcRect.getPreciseCopy();
+ baseRect.translate(moveDelta);
+ jointRect.translate(moveDelta);
+
+ PrecisionPoint preciseDelta = new PrecisionPoint(moveDelta);
+ snapToHelper.snapPoint(request, PositionConstants.HORIZONTAL | PositionConstants.VERTICAL, new PrecisionRectangle[] { baseRect, jointRect }, preciseDelta);
+ request.setMoveDelta(preciseDelta);
+ }
+ }
+
+
+ // -----------------------------added methods for Papyrus
+ protected PrecisionRectangle getSourceRectangle() {
+ return this.sourceRectangle.getPreciseCopy();
+ }
+
+ protected SnapToHelper getSnapToHelper() {
+ return this.snapToHelper;
+ }
+
+ protected PrecisionRectangle getCompoundSourceRectangle() {
+ return this.compoundSrcRect.getPreciseCopy();
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DelayedDirectEditHelper.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DelayedDirectEditHelper.java
index 4cf59936bc7..b9587e1aab3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DelayedDirectEditHelper.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DelayedDirectEditHelper.java
@@ -1,129 +1,129 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.Request;
-import org.eclipse.swt.events.FocusAdapter;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * @author hudsonr Created on Mar 6, 2003
- */
-class DelayedDirectEditHelper implements Runnable {
-
- private EditPartViewer viewer;
-
- private EditPart part;
-
- private Request req;
-
- private FocusListener focus;
-
- private MouseListener mouse;
-
- private KeyListener key;
-
- private static DelayedDirectEditHelper activeHelper;
-
- /**
- * Constructs a new helper and starts it immediately. If another helper is
- * active, it is aborted and neither helper will run.
- *
- * @param viewer
- * the viewer on which the direct-edit is supposed to happen
- * @param request
- * the request that triggered the direct-edit
- * @param receiver
- * the EditPart that received the request
- */
- public DelayedDirectEditHelper(EditPartViewer viewer, Request request, EditPart receiver) {
- this.req = request;
- this.viewer = viewer;
- this.part = receiver;
- if (activeHelper != null) {
- activeHelper = null;
- } else {
- hookControl(viewer.getControl());
- activeHelper = this;
- Display.getCurrent().timerExec(400, this);
- }
- }
-
- /**
- * The edit is canceled by setting the active helper to <code>null</code>.
- */
- void abort() {
- activeHelper = null;
- }
-
- void hookControl(Control control) {
- control.addFocusListener(focus = new FocusAdapter() {
-
- @Override
- public void focusLost(FocusEvent e) {
- abort();
- }
- });
- control.addKeyListener(key = new KeyListener() {
-
- @Override
- public void keyPressed(KeyEvent e) {
- abort();
- }
-
- @Override
- public void keyReleased(KeyEvent e) {
- abort();
- }
- });
-
- control.addMouseListener(mouse = new MouseAdapter() {
-
- @Override
- public void mouseDoubleClick(MouseEvent e) {
- abort();
- }
-
- @Override
- public void mouseDown(MouseEvent e) {
- abort();
- }
- });
- }
-
- /**
- * If this helper has not been aborted, the target editpart will be sent the
- * request.
- */
- @Override
- public void run() {
- if (activeHelper == this && part.isActive() && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
- part.performRequest(req);
- }
- if (viewer.getControl() != null && !viewer.getControl().isDisposed()) {
- viewer.getControl().removeFocusListener(focus);
- viewer.getControl().removeMouseListener(mouse);
- viewer.getControl().removeKeyListener(key);
- }
- activeHelper = null;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.Request;
+import org.eclipse.swt.events.FocusAdapter;
+import org.eclipse.swt.events.FocusEvent;
+import org.eclipse.swt.events.FocusListener;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseListener;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * @author hudsonr Created on Mar 6, 2003
+ */
+class DelayedDirectEditHelper implements Runnable {
+
+ private EditPartViewer viewer;
+
+ private EditPart part;
+
+ private Request req;
+
+ private FocusListener focus;
+
+ private MouseListener mouse;
+
+ private KeyListener key;
+
+ private static DelayedDirectEditHelper activeHelper;
+
+ /**
+ * Constructs a new helper and starts it immediately. If another helper is
+ * active, it is aborted and neither helper will run.
+ *
+ * @param viewer
+ * the viewer on which the direct-edit is supposed to happen
+ * @param request
+ * the request that triggered the direct-edit
+ * @param receiver
+ * the EditPart that received the request
+ */
+ public DelayedDirectEditHelper(EditPartViewer viewer, Request request, EditPart receiver) {
+ this.req = request;
+ this.viewer = viewer;
+ this.part = receiver;
+ if (activeHelper != null) {
+ activeHelper = null;
+ } else {
+ hookControl(viewer.getControl());
+ activeHelper = this;
+ Display.getCurrent().timerExec(400, this);
+ }
+ }
+
+ /**
+ * The edit is canceled by setting the active helper to <code>null</code>.
+ */
+ void abort() {
+ activeHelper = null;
+ }
+
+ void hookControl(Control control) {
+ control.addFocusListener(focus = new FocusAdapter() {
+
+ @Override
+ public void focusLost(FocusEvent e) {
+ abort();
+ }
+ });
+ control.addKeyListener(key = new KeyListener() {
+
+ @Override
+ public void keyPressed(KeyEvent e) {
+ abort();
+ }
+
+ @Override
+ public void keyReleased(KeyEvent e) {
+ abort();
+ }
+ });
+
+ control.addMouseListener(mouse = new MouseAdapter() {
+
+ @Override
+ public void mouseDoubleClick(MouseEvent e) {
+ abort();
+ }
+
+ @Override
+ public void mouseDown(MouseEvent e) {
+ abort();
+ }
+ });
+ }
+
+ /**
+ * If this helper has not been aborted, the target editpart will be sent the
+ * request.
+ */
+ @Override
+ public void run() {
+ if (activeHelper == this && part.isActive() && viewer.getControl() != null && !viewer.getControl().isDisposed()) {
+ part.performRequest(req);
+ }
+ if (viewer.getControl() != null && !viewer.getControl().isDisposed()) {
+ viewer.getControl().removeFocusListener(focus);
+ viewer.getControl().removeMouseListener(mouse);
+ viewer.getControl().removeKeyListener(key);
+ }
+ activeHelper = null;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DragEditPartsTrackerEx.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DragEditPartsTrackerEx.java
index 73360886d8c..d6c63ffce3a 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DragEditPartsTrackerEx.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/DragEditPartsTrackerEx.java
@@ -1,321 +1,321 @@
-/******************************************************************************
- * Copyright (c) 2002, 2008 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.papyrus.infra.gmfdiag.common.snap.copy;
-
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.draw2d.Cursors;
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.PositionConstants;
-import org.eclipse.draw2d.Viewport;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.CompoundCommand;
-import org.eclipse.gef.requests.ChangeBoundsRequest;
-import org.eclipse.gef.tools.ToolUtilities;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GroupEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
-import org.eclipse.gmf.runtime.diagram.ui.requests.DuplicateRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
-import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.widgets.Control;
-
-/**
- * A dervied DragEditPartsTRacker that sends REQ_DRAG instead of REQ_ORPHAN
- * and REQ_DROP instead of REQ_ADD
- *
- * @author melaasar
- */
-@SuppressWarnings("restriction")
-public class DragEditPartsTrackerEx extends CustomDragEditPartsTracker {
-
- /**
- * @param sourceEditPart
- */
- public DragEditPartsTrackerEx(EditPart sourceEditPart) {
- super(sourceEditPart);
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getCommand()
- */
- @Override
- protected Command getCommand() {
- if (!isMove()) {
- CompoundCommand command = new CompoundCommand();
- addSourceCommands(false, command);
- if (getTargetEditPart() != null) {
- command.add(getTargetEditPart().getCommand(getTargetRequest()));
- if (command.canExecute()) {
- return command;
- }
- }
-
-
- }
- CompoundCommand command = new CompoundCommand();
- addSourceCommands(true, command);
- return command;
- }
-
- /**
- * Collects the move/drag commands from the operation set
- *
- * @param isMove
- * @param command
- */
- protected void addSourceCommands(boolean isMove, CompoundCommand command) {
- Request request = getTargetRequest();
-
- if (isCloneActive()) {
-
- // do not use operation set in this case as connections will get
- // filtered out
- List editparts = ToolUtilities
- .getSelectionWithoutDependants(getCurrentViewer());
-
- DuplicateRequest duplicateRequest = new DuplicateRequest();
- duplicateRequest.setEditParts(editparts);
- duplicateRequest.setExtendedData(request.getExtendedData());
- if (request instanceof ChangeBoundsRequest) {
- Point delta = ((ChangeBoundsRequest) request).getMoveDelta();
- MapModeUtil.getMapMode(
- ((IGraphicalEditPart) getTargetEditPart()).getFigure())
- .DPtoLP(delta);
-
- duplicateRequest.setOffset(delta);
- }
- command.add(getTargetEditPart().getCommand(duplicateRequest));
- } else {
- request.setType(isMove ? REQ_MOVE
- : RequestConstants.REQ_DRAG);
- Iterator iter = getOperationSet().iterator();
- while (iter.hasNext()) {
- EditPart editPart = (EditPart) iter.next();
- command.add(editPart.getCommand(request));
- }
- }
-
- request.setType(RequestConstants.REQ_DROP);
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
- */
- @Override
- protected String getCommandName() {
- if (!isMove()) {
- return RequestConstants.REQ_DROP;
- }
- return super.getCommandName();
- }
-
- /**
- * If the source is not in the operation set, it is not a move
- *
- * @see org.eclipse.gef.tool s.DragEditPartsTracker#isMove()
- */
- @Override
- 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()
- */
- @Override
- protected void executeCurrentCommand() {
- super.executeCurrentCommand();
- if (isActive()) {
- if (getOperationSet().size() > 0) {
- if (getOperationSet().get(0) instanceof IGraphicalEditPart) {
- IGraphicalEditPart editpart = (IGraphicalEditPart) getOperationSet()
- .get(0);
- if ((editpart.getFigure() == null)
- || (editpart.getFigure().getParent() == null)
- || (editpart.getFigure().getParent().getLayoutManager() == null)) {
- return;
- }
- editpart.getFigure().getParent().getLayoutManager().layout(
- editpart.getFigure().getParent());
- reveal(editpart);
- }
- }
- }
- }
-
- /**
- * @param editpart
- */
- protected void reveal(EditPart editpart) {
- editpart.getViewer().reveal(editpart);
- }
-
- @Override
- protected boolean handleDragInProgress() {
- boolean returnValue = super.handleDragInProgress();
- if (isInState(STATE_DRAG_IN_PROGRESS)
- || isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
-
- // Expose the diagram as the user scrolls in the area handled by the
- // autoexpose helper.
- updateAutoexposeHelper();
- }
- return returnValue;
- }
-
- @Override
- protected Cursor calculateCursor() {
- if (isInState(STATE_DRAG_IN_PROGRESS)
- || isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
-
- // Give some feedback so the user knows the area where autoscrolling
- // will occur.
- if (getAutoexposeHelper() != null) {
- return Cursors.HAND;
- } else {
-
- // Give some feedback so the user knows that they can't drag
- // outside the viewport.
- Control control = getCurrentViewer().getControl();
- if (control instanceof FigureCanvas) {
- Viewport viewport = ((FigureCanvas) control).getViewport();
- Rectangle rect = Rectangle.SINGLETON;
- viewport.getClientArea(rect);
- viewport.translateToParent(rect);
- viewport.translateToAbsolute(rect);
-
- if (!rect.contains(getLocation())) {
- return getDisabledCursor();
- }
- }
- }
- }
- return super.calculateCursor();
- }
-
- @Override
- protected boolean handleButtonDown(int button) {
-
- // If the group is selected, and the user clicks on a shape, defer the
- // selection of the shape until the mouse button is released instead of
- // selecting on mouse down because if the user does a drag they will
- // move the entire group and not the shape.
- if (button == 1
- && getSourceEditPart().getParent() instanceof GroupEditPart
- && getSourceEditPart().getParent().getSelected() != EditPart.SELECTED_NONE) {
-
- stateTransition(STATE_INITIAL, STATE_DRAG);
- return true;
- }
-
- return super.handleButtonDown(button);
- }
-
- @Override
- protected boolean handleDoubleClick(int button) {
- // If the user double-clicks a shape in a group and the shape is not
- // selected, select the shape.
- if (getSourceEditPart().getParent() instanceof GroupEditPart
- && getSourceEditPart().getSelected() == EditPart.SELECTED_NONE) {
- performSelection();
- return true;
- } else {
- return super.handleDoubleClick(button);
- }
- }
-
- @Override
- protected void performSelection() {
- super.performSelection();
-
- // If the new selection is a child of a group, we want to deselect the group.
- if (getSourceEditPart().getParent() instanceof GroupEditPart
- && getSourceEditPart().getParent().getSelected() != EditPart.SELECTED_NONE) {
- getCurrentViewer().deselect(getSourceEditPart().getParent());
- }
- }
-
- /**
- * Overridden to add extended data to the request to restrict snapping to
- * specific directions based on the move delta.
- */
- @Override
- protected void snapPoint(ChangeBoundsRequest request) {
- Point moveDelta = request.getMoveDelta();
- if (getState() == STATE_ACCESSIBLE_DRAG_IN_PROGRESS) {
- int restrictedDirection = 0;
-
- if (moveDelta.x > 0) {
- restrictedDirection = restrictedDirection
- | PositionConstants.EAST;
- } else if (moveDelta.x < 0) {
- restrictedDirection = restrictedDirection
- | PositionConstants.WEST;
- }
-
- if (moveDelta.y > 0) {
- restrictedDirection = restrictedDirection
- | PositionConstants.SOUTH;
- } else if (moveDelta.y < 0) {
- restrictedDirection = restrictedDirection
- | PositionConstants.NORTH;
- }
-
- request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS,
- restrictedDirection);
- }
-
- super.snapPoint(request);
- }
-
- @Override
- protected boolean handleKeyDown(KeyEvent e) {
- if (acceptArrowKey(e)) {
- if (isInState(STATE_INITIAL)) {
- IGraphicalEditPart ep = (IGraphicalEditPart) getSourceEditPart();
- if (ep != null) {
- Point location = ep.getFigure().getBounds().getCenter();
- ep.getFigure().translateToAbsolute(location);
- placeMouseInViewer(location);
- getCurrentInput().setMouseLocation(location.x, location.y);
- }
- }
- }
- return super.handleKeyDown(e);
- }
-
-}
+/******************************************************************************
+ * Copyright (c) 2002, 2008 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.papyrus.infra.gmfdiag.common.snap.copy;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.draw2d.Cursors;
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.PositionConstants;
+import org.eclipse.draw2d.Viewport;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.CompoundCommand;
+import org.eclipse.gef.requests.ChangeBoundsRequest;
+import org.eclipse.gef.tools.ToolUtilities;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GroupEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.internal.ruler.SnapToHelperUtil;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DuplicateRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.RequestConstants;
+import org.eclipse.gmf.runtime.draw2d.ui.mapmode.MapModeUtil;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.widgets.Control;
+
+/**
+ * A dervied DragEditPartsTRacker that sends REQ_DRAG instead of REQ_ORPHAN
+ * and REQ_DROP instead of REQ_ADD
+ *
+ * @author melaasar
+ */
+@SuppressWarnings("restriction")
+public class DragEditPartsTrackerEx extends CustomDragEditPartsTracker {
+
+ /**
+ * @param sourceEditPart
+ */
+ public DragEditPartsTrackerEx(EditPart sourceEditPart) {
+ super(sourceEditPart);
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getCommand()
+ */
+ @Override
+ protected Command getCommand() {
+ if (!isMove()) {
+ CompoundCommand command = new CompoundCommand();
+ addSourceCommands(false, command);
+ if (getTargetEditPart() != null) {
+ command.add(getTargetEditPart().getCommand(getTargetRequest()));
+ if (command.canExecute()) {
+ return command;
+ }
+ }
+
+
+ }
+ CompoundCommand command = new CompoundCommand();
+ addSourceCommands(true, command);
+ return command;
+ }
+
+ /**
+ * Collects the move/drag commands from the operation set
+ *
+ * @param isMove
+ * @param command
+ */
+ protected void addSourceCommands(boolean isMove, CompoundCommand command) {
+ Request request = getTargetRequest();
+
+ if (isCloneActive()) {
+
+ // do not use operation set in this case as connections will get
+ // filtered out
+ List editparts = ToolUtilities
+ .getSelectionWithoutDependants(getCurrentViewer());
+
+ DuplicateRequest duplicateRequest = new DuplicateRequest();
+ duplicateRequest.setEditParts(editparts);
+ duplicateRequest.setExtendedData(request.getExtendedData());
+ if (request instanceof ChangeBoundsRequest) {
+ Point delta = ((ChangeBoundsRequest) request).getMoveDelta();
+ MapModeUtil.getMapMode(
+ ((IGraphicalEditPart) getTargetEditPart()).getFigure())
+ .DPtoLP(delta);
+
+ duplicateRequest.setOffset(delta);
+ }
+ command.add(getTargetEditPart().getCommand(duplicateRequest));
+ } else {
+ request.setType(isMove ? REQ_MOVE
+ : RequestConstants.REQ_DRAG);
+ Iterator iter = getOperationSet().iterator();
+ while (iter.hasNext()) {
+ EditPart editPart = (EditPart) iter.next();
+ command.add(editPart.getCommand(request));
+ }
+ }
+
+ request.setType(RequestConstants.REQ_DROP);
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
+ */
+ @Override
+ protected String getCommandName() {
+ if (!isMove()) {
+ return RequestConstants.REQ_DROP;
+ }
+ return super.getCommandName();
+ }
+
+ /**
+ * If the source is not in the operation set, it is not a move
+ *
+ * @see org.eclipse.gef.tool s.DragEditPartsTracker#isMove()
+ */
+ @Override
+ 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()
+ */
+ @Override
+ protected void executeCurrentCommand() {
+ super.executeCurrentCommand();
+ if (isActive()) {
+ if (getOperationSet().size() > 0) {
+ if (getOperationSet().get(0) instanceof IGraphicalEditPart) {
+ IGraphicalEditPart editpart = (IGraphicalEditPart) getOperationSet()
+ .get(0);
+ if ((editpart.getFigure() == null)
+ || (editpart.getFigure().getParent() == null)
+ || (editpart.getFigure().getParent().getLayoutManager() == null)) {
+ return;
+ }
+ editpart.getFigure().getParent().getLayoutManager().layout(
+ editpart.getFigure().getParent());
+ reveal(editpart);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param editpart
+ */
+ protected void reveal(EditPart editpart) {
+ editpart.getViewer().reveal(editpart);
+ }
+
+ @Override
+ protected boolean handleDragInProgress() {
+ boolean returnValue = super.handleDragInProgress();
+ if (isInState(STATE_DRAG_IN_PROGRESS)
+ || isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
+
+ // Expose the diagram as the user scrolls in the area handled by the
+ // autoexpose helper.
+ updateAutoexposeHelper();
+ }
+ return returnValue;
+ }
+
+ @Override
+ protected Cursor calculateCursor() {
+ if (isInState(STATE_DRAG_IN_PROGRESS)
+ || isInState(STATE_ACCESSIBLE_DRAG_IN_PROGRESS)) {
+
+ // Give some feedback so the user knows the area where autoscrolling
+ // will occur.
+ if (getAutoexposeHelper() != null) {
+ return Cursors.HAND;
+ } else {
+
+ // Give some feedback so the user knows that they can't drag
+ // outside the viewport.
+ Control control = getCurrentViewer().getControl();
+ if (control instanceof FigureCanvas) {
+ Viewport viewport = ((FigureCanvas) control).getViewport();
+ Rectangle rect = Rectangle.SINGLETON;
+ viewport.getClientArea(rect);
+ viewport.translateToParent(rect);
+ viewport.translateToAbsolute(rect);
+
+ if (!rect.contains(getLocation())) {
+ return getDisabledCursor();
+ }
+ }
+ }
+ }
+ return super.calculateCursor();
+ }
+
+ @Override
+ protected boolean handleButtonDown(int button) {
+
+ // If the group is selected, and the user clicks on a shape, defer the
+ // selection of the shape until the mouse button is released instead of
+ // selecting on mouse down because if the user does a drag they will
+ // move the entire group and not the shape.
+ if (button == 1
+ && getSourceEditPart().getParent() instanceof GroupEditPart
+ && getSourceEditPart().getParent().getSelected() != EditPart.SELECTED_NONE) {
+
+ stateTransition(STATE_INITIAL, STATE_DRAG);
+ return true;
+ }
+
+ return super.handleButtonDown(button);
+ }
+
+ @Override
+ protected boolean handleDoubleClick(int button) {
+ // If the user double-clicks a shape in a group and the shape is not
+ // selected, select the shape.
+ if (getSourceEditPart().getParent() instanceof GroupEditPart
+ && getSourceEditPart().getSelected() == EditPart.SELECTED_NONE) {
+ performSelection();
+ return true;
+ } else {
+ return super.handleDoubleClick(button);
+ }
+ }
+
+ @Override
+ protected void performSelection() {
+ super.performSelection();
+
+ // If the new selection is a child of a group, we want to deselect the group.
+ if (getSourceEditPart().getParent() instanceof GroupEditPart
+ && getSourceEditPart().getParent().getSelected() != EditPart.SELECTED_NONE) {
+ getCurrentViewer().deselect(getSourceEditPart().getParent());
+ }
+ }
+
+ /**
+ * Overridden to add extended data to the request to restrict snapping to
+ * specific directions based on the move delta.
+ */
+ @Override
+ protected void snapPoint(ChangeBoundsRequest request) {
+ Point moveDelta = request.getMoveDelta();
+ if (getState() == STATE_ACCESSIBLE_DRAG_IN_PROGRESS) {
+ int restrictedDirection = 0;
+
+ if (moveDelta.x > 0) {
+ restrictedDirection = restrictedDirection
+ | PositionConstants.EAST;
+ } else if (moveDelta.x < 0) {
+ restrictedDirection = restrictedDirection
+ | PositionConstants.WEST;
+ }
+
+ if (moveDelta.y > 0) {
+ restrictedDirection = restrictedDirection
+ | PositionConstants.SOUTH;
+ } else if (moveDelta.y < 0) {
+ restrictedDirection = restrictedDirection
+ | PositionConstants.NORTH;
+ }
+
+ request.getExtendedData().put(SnapToHelperUtil.RESTRICTED_DIRECTIONS,
+ restrictedDirection);
+ }
+
+ super.snapPoint(request);
+ }
+
+ @Override
+ protected boolean handleKeyDown(KeyEvent e) {
+ if (acceptArrowKey(e)) {
+ if (isInState(STATE_INITIAL)) {
+ IGraphicalEditPart ep = (IGraphicalEditPart) getSourceEditPart();
+ if (ep != null) {
+ Point location = ep.getFigure().getBounds().getCenter();
+ ep.getFigure().translateToAbsolute(location);
+ placeMouseInViewer(location);
+ getCurrentInput().setMouseLocation(location.x, location.y);
+ }
+ }
+ }
+ return super.handleKeyDown(e);
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/SelectEditPartTracker.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/SelectEditPartTracker.java
index 2d2a7e701a1..193215b9e88 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/SelectEditPartTracker.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/SelectEditPartTracker.java
@@ -1,259 +1,259 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
-
-import java.util.List;
-
-import org.eclipse.gef.DragTracker;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.RequestConstants;
-import org.eclipse.gef.requests.DirectEditRequest;
-import org.eclipse.gef.requests.SelectionRequest;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Cursor;
-
-/**
- * DragTracker used to select, edit, and open {@link org.eclipse.gef.EditPart
- * EditParts}.
- */
-public class SelectEditPartTracker extends TargetingTool implements DragTracker {
-
- /** Flag to indicate selection has been performed. */
- protected static final int FLAG_SELECTION_PERFORMED = TargetingTool.MAX_FLAG << 1;
-
- private static final int FLAG_ENABLE_DIRECT_EDIT = TargetingTool.MAX_FLAG << 2;
-
- /** Max flag */
- protected static final int MAX_FLAG = FLAG_ENABLE_DIRECT_EDIT;
-
- private EditPart editpart;
-
- /**
- * Constructs a new SelectEditPartTracker with the given edit part as the
- * source.
- *
- * @param owner
- * the source edit part
- */
- public SelectEditPartTracker(EditPart owner) {
- setSourceEditPart(owner);
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#calculateCursor()
- */
- @Override
- protected Cursor calculateCursor() {
- if (isInState(STATE_INITIAL | STATE_DRAG | STATE_ACCESSIBLE_DRAG)) {
- return getDefaultCursor();
- }
- return super.calculateCursor();
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
- */
- @Override
- protected String getCommandName() {
- return "Select Tracker";//$NON-NLS-1$
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
- */
- @Override
- protected String getDebugName() {
- return "Select Tracker";//$NON-NLS-1$
- }
-
- /**
- * Returns the source edit part.
- *
- * @return the source edit part
- */
- protected EditPart getSourceEditPart() {
- return editpart;
- }
-
- /**
- * Performs a conditional selection if needed (if right or left mouse button
- * have been pressed) and goes into the drag state. If any other button has
- * been pressed, the tool goes into the invalid state.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleButtonDown(int)
- */
- @Override
- protected boolean handleButtonDown(int button) {
- if ((button == 3 || button == 1) && isInState(STATE_INITIAL)) {
- performConditionalSelection();
- }
-
- if (button != 1) {
- setState(STATE_INVALID);
- if (button == 3) {
- setState(STATE_TERMINAL);
- }
- handleInvalidInput();
- } else {
- stateTransition(STATE_INITIAL, STATE_DRAG);
- }
- return true;
- }
-
- /**
- * If in the drag state, the tool selects the source edit part. If the edit
- * part was already selected, {@link #performDirectEdit()} is called. If the
- * edit part is newly selected and not completely visible, {@link EditPartViewer#reveal(EditPart)} is called to show the selected
- * edit part.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
- */
- @Override
- protected boolean handleButtonUp(int button) {
- if (isInState(STATE_DRAG)) {
- performSelection();
- if (getFlag(FLAG_ENABLE_DIRECT_EDIT)) {
- performDirectEdit();
- }
- if (button == 1 && getSourceEditPart().getSelected() != EditPart.SELECTED_NONE) {
- getCurrentViewer().reveal(getSourceEditPart());
- }
- setState(STATE_TERMINAL);
- return true;
- }
- return false;
- }
-
- /**
- * Calls {@link #performOpen()} if the double click was with mouse button 1.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleDoubleClick(int)
- */
- @Override
- protected boolean handleDoubleClick(int button) {
- setFlag(FLAG_ENABLE_DIRECT_EDIT, false);
- if (button == 1) {
- // Prevent selection from happening later on mouse up
- setFlag(FLAG_SELECTION_PERFORMED, true);
- performOpen();
- }
- return true;
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#handleDragStarted()
- */
- @Override
- protected boolean handleDragStarted() {
- return stateTransition(STATE_DRAG, STATE_DRAG_IN_PROGRESS);
- }
-
- /**
- * Returns <code>true</code> if selection has already occured.
- *
- * @return <code>true</code> if selection has occured
- */
- protected boolean hasSelectionOccurred() {
- return getFlag(FLAG_SELECTION_PERFORMED);
- }
-
- /**
- * Calls {@link #performSelection()} if the source is not selected. If the
- * source is selected and there are no modifier keys pressed (i.e. the user
- * isn't selecting multiple edit parts or deselecting edit parts), sets the
- * direct edit flag so that when the mouse is released, a direct edit will
- * be performed.
- */
- protected void performConditionalSelection() {
- if (getSourceEditPart().getSelected() == EditPart.SELECTED_NONE) {
- performSelection();
- } else if (getCurrentInput().getModifiers() == 0) {
- setFlag(FLAG_ENABLE_DIRECT_EDIT, true);
- }
- }
-
- /**
- * Creates a {@link DirectEditRequest} and sends it to a
- * DelayedDirectEditHelper to allow the user to directly edit the edit part.
- */
- protected void performDirectEdit() {
- DirectEditRequest req = new DirectEditRequest();
- req.setLocation(getCurrentInput().getMouseLocation());
- new DelayedDirectEditHelper(getSourceEditPart().getViewer(), req, getSourceEditPart());
- }
-
- /**
- * Creates a {@link SelectionRequest} and sends it to the source edit part
- * via {@link EditPart#performRequest(Request)}. Possible uses are to open
- * the selected item in another editor or replace the current editor's
- * contents based on the selected item.
- */
- protected void performOpen() {
- SelectionRequest request = new SelectionRequest();
- request.setLocation(getLocation());
- request.setModifiers(getCurrentInput().getModifiers());
- request.setType(RequestConstants.REQ_OPEN);
- getSourceEditPart().performRequest(request);
- }
-
- /**
- * Performs the appropriate selection action based on the selection state of
- * the source and the modifiers (CTRL and SHIFT). If no modifier key is
- * pressed, the source will be set as the only selection. If the CTRL key is
- * pressed and the edit part is already selected, it will be deselected. If
- * the CTRL key is pressed and the edit part is not selected, it will be
- * appended to the selection set. If the SHIFT key is pressed, the source
- * will be appended to the selection.
- */
- protected void performSelection() {
- if (hasSelectionOccurred()) {
- return;
- }
- setFlag(FLAG_SELECTION_PERFORMED, true);
- EditPartViewer viewer = getCurrentViewer();
- List selectedObjects = viewer.getSelectedEditParts();
-
- if (getCurrentInput().isModKeyDown(SWT.MOD1)) {
- if (selectedObjects.contains(getSourceEditPart())) {
- viewer.deselect(getSourceEditPart());
- } else {
- viewer.appendSelection(getSourceEditPart());
- }
- } else if (getCurrentInput().isShiftKeyDown()) {
- viewer.appendSelection(getSourceEditPart());
- } else {
- viewer.select(getSourceEditPart());
- }
- }
-
- /**
- * @see org.eclipse.gef.tools.AbstractTool#resetFlags()
- */
- @Override
- protected void resetFlags() {
- super.resetFlags();
- setFlag(FLAG_SELECTION_PERFORMED, false);
- setFlag(FLAG_ENABLE_DIRECT_EDIT, false);
- }
-
- /**
- * Sets the source edit part.
- *
- * @param part
- * the source edit part
- */
- protected void setSourceEditPart(EditPart part) {
- this.editpart = part;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
+
+import java.util.List;
+
+import org.eclipse.gef.DragTracker;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.RequestConstants;
+import org.eclipse.gef.requests.DirectEditRequest;
+import org.eclipse.gef.requests.SelectionRequest;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Cursor;
+
+/**
+ * DragTracker used to select, edit, and open {@link org.eclipse.gef.EditPart
+ * EditParts}.
+ */
+public class SelectEditPartTracker extends TargetingTool implements DragTracker {
+
+ /** Flag to indicate selection has been performed. */
+ protected static final int FLAG_SELECTION_PERFORMED = TargetingTool.MAX_FLAG << 1;
+
+ private static final int FLAG_ENABLE_DIRECT_EDIT = TargetingTool.MAX_FLAG << 2;
+
+ /** Max flag */
+ protected static final int MAX_FLAG = FLAG_ENABLE_DIRECT_EDIT;
+
+ private EditPart editpart;
+
+ /**
+ * Constructs a new SelectEditPartTracker with the given edit part as the
+ * source.
+ *
+ * @param owner
+ * the source edit part
+ */
+ public SelectEditPartTracker(EditPart owner) {
+ setSourceEditPart(owner);
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#calculateCursor()
+ */
+ @Override
+ protected Cursor calculateCursor() {
+ if (isInState(STATE_INITIAL | STATE_DRAG | STATE_ACCESSIBLE_DRAG)) {
+ return getDefaultCursor();
+ }
+ return super.calculateCursor();
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getCommandName()
+ */
+ @Override
+ protected String getCommandName() {
+ return "Select Tracker";//$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#getDebugName()
+ */
+ @Override
+ protected String getDebugName() {
+ return "Select Tracker";//$NON-NLS-1$
+ }
+
+ /**
+ * Returns the source edit part.
+ *
+ * @return the source edit part
+ */
+ protected EditPart getSourceEditPart() {
+ return editpart;
+ }
+
+ /**
+ * Performs a conditional selection if needed (if right or left mouse button
+ * have been pressed) and goes into the drag state. If any other button has
+ * been pressed, the tool goes into the invalid state.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleButtonDown(int)
+ */
+ @Override
+ protected boolean handleButtonDown(int button) {
+ if ((button == 3 || button == 1) && isInState(STATE_INITIAL)) {
+ performConditionalSelection();
+ }
+
+ if (button != 1) {
+ setState(STATE_INVALID);
+ if (button == 3) {
+ setState(STATE_TERMINAL);
+ }
+ handleInvalidInput();
+ } else {
+ stateTransition(STATE_INITIAL, STATE_DRAG);
+ }
+ return true;
+ }
+
+ /**
+ * If in the drag state, the tool selects the source edit part. If the edit
+ * part was already selected, {@link #performDirectEdit()} is called. If the
+ * edit part is newly selected and not completely visible, {@link EditPartViewer#reveal(EditPart)} is called to show the selected
+ * edit part.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleButtonUp(int)
+ */
+ @Override
+ protected boolean handleButtonUp(int button) {
+ if (isInState(STATE_DRAG)) {
+ performSelection();
+ if (getFlag(FLAG_ENABLE_DIRECT_EDIT)) {
+ performDirectEdit();
+ }
+ if (button == 1 && getSourceEditPart().getSelected() != EditPart.SELECTED_NONE) {
+ getCurrentViewer().reveal(getSourceEditPart());
+ }
+ setState(STATE_TERMINAL);
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Calls {@link #performOpen()} if the double click was with mouse button 1.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleDoubleClick(int)
+ */
+ @Override
+ protected boolean handleDoubleClick(int button) {
+ setFlag(FLAG_ENABLE_DIRECT_EDIT, false);
+ if (button == 1) {
+ // Prevent selection from happening later on mouse up
+ setFlag(FLAG_SELECTION_PERFORMED, true);
+ performOpen();
+ }
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#handleDragStarted()
+ */
+ @Override
+ protected boolean handleDragStarted() {
+ return stateTransition(STATE_DRAG, STATE_DRAG_IN_PROGRESS);
+ }
+
+ /**
+ * Returns <code>true</code> if selection has already occured.
+ *
+ * @return <code>true</code> if selection has occured
+ */
+ protected boolean hasSelectionOccurred() {
+ return getFlag(FLAG_SELECTION_PERFORMED);
+ }
+
+ /**
+ * Calls {@link #performSelection()} if the source is not selected. If the
+ * source is selected and there are no modifier keys pressed (i.e. the user
+ * isn't selecting multiple edit parts or deselecting edit parts), sets the
+ * direct edit flag so that when the mouse is released, a direct edit will
+ * be performed.
+ */
+ protected void performConditionalSelection() {
+ if (getSourceEditPart().getSelected() == EditPart.SELECTED_NONE) {
+ performSelection();
+ } else if (getCurrentInput().getModifiers() == 0) {
+ setFlag(FLAG_ENABLE_DIRECT_EDIT, true);
+ }
+ }
+
+ /**
+ * Creates a {@link DirectEditRequest} and sends it to a
+ * DelayedDirectEditHelper to allow the user to directly edit the edit part.
+ */
+ protected void performDirectEdit() {
+ DirectEditRequest req = new DirectEditRequest();
+ req.setLocation(getCurrentInput().getMouseLocation());
+ new DelayedDirectEditHelper(getSourceEditPart().getViewer(), req, getSourceEditPart());
+ }
+
+ /**
+ * Creates a {@link SelectionRequest} and sends it to the source edit part
+ * via {@link EditPart#performRequest(Request)}. Possible uses are to open
+ * the selected item in another editor or replace the current editor's
+ * contents based on the selected item.
+ */
+ protected void performOpen() {
+ SelectionRequest request = new SelectionRequest();
+ request.setLocation(getLocation());
+ request.setModifiers(getCurrentInput().getModifiers());
+ request.setType(RequestConstants.REQ_OPEN);
+ getSourceEditPart().performRequest(request);
+ }
+
+ /**
+ * Performs the appropriate selection action based on the selection state of
+ * the source and the modifiers (CTRL and SHIFT). If no modifier key is
+ * pressed, the source will be set as the only selection. If the CTRL key is
+ * pressed and the edit part is already selected, it will be deselected. If
+ * the CTRL key is pressed and the edit part is not selected, it will be
+ * appended to the selection set. If the SHIFT key is pressed, the source
+ * will be appended to the selection.
+ */
+ protected void performSelection() {
+ if (hasSelectionOccurred()) {
+ return;
+ }
+ setFlag(FLAG_SELECTION_PERFORMED, true);
+ EditPartViewer viewer = getCurrentViewer();
+ List selectedObjects = viewer.getSelectedEditParts();
+
+ if (getCurrentInput().isModKeyDown(SWT.MOD1)) {
+ if (selectedObjects.contains(getSourceEditPart())) {
+ viewer.deselect(getSourceEditPart());
+ } else {
+ viewer.appendSelection(getSourceEditPart());
+ }
+ } else if (getCurrentInput().isShiftKeyDown()) {
+ viewer.appendSelection(getSourceEditPart());
+ } else {
+ viewer.select(getSourceEditPart());
+ }
+ }
+
+ /**
+ * @see org.eclipse.gef.tools.AbstractTool#resetFlags()
+ */
+ @Override
+ protected void resetFlags() {
+ super.resetFlags();
+ setFlag(FLAG_SELECTION_PERFORMED, false);
+ setFlag(FLAG_ENABLE_DIRECT_EDIT, false);
+ }
+
+ /**
+ * Sets the source edit part.
+ *
+ * @param part
+ * the source edit part
+ */
+ protected void setSourceEditPart(EditPart part) {
+ this.editpart = part;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/TargetingTool.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/TargetingTool.java
index 4e7bb34c3dc..ec042ce16b2 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/TargetingTool.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/snap/copy/TargetingTool.java
@@ -1,457 +1,457 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.gef.AutoexposeHelper;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gef.commands.UnexecutableCommand;
-import org.eclipse.gef.requests.TargetRequest;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * The base implementation for tools which perform targeting of editparts.
- * Targeting tools may operate using either mouse drags or just mouse moves.
- * Targeting tools work with a <i>target</i> request. This request is used along
- * with the mouse location to obtain an active target from the current
- * EditPartViewer. This target is then asked for the <code>Command</code> that
- * performs the given request. The target is also asked to show target feedback.
- * <P>
- * TargetingTool also provides support for auto-expose (a.k.a. auto-scrolling). Subclasses that wish to commence auto-expose can do so by calling {@link #updateAutoexposeHelper()}. An an AutoExposeHelper is found, auto-scrolling begins. Whenever that helper
- * scrolls the diagram of performs any other change, <code>handleMove</code> will be called as if the mouse had moved. This is because the target has probably moved, but there is no input event to trigger an update of the operation.
- */
-public abstract class TargetingTool extends AbstractTool {
-
- private static final int FLAG_LOCK_TARGET = AbstractTool.MAX_FLAG << 1;
-
- private static final int FLAG_TARGET_FEEDBACK = AbstractTool.MAX_FLAG << 2;
-
- /**
- * The max flag.
- */
- protected static final int MAX_FLAG = FLAG_TARGET_FEEDBACK;
-
- private Request targetRequest;
-
- private EditPart targetEditPart;
-
- private AutoexposeHelper exposeHelper;
-
- /**
- * Creates the target request that will be used with the target editpart.
- * This request will be cached and updated as needed.
- *
- * @see #getTargetRequest()
- * @return the new target request
- */
- protected Request createTargetRequest() {
- Request request = new Request();
- request.setType(getCommandName());
- return request;
- }
-
- /**
- * @see org.eclipse.gef.Tool#deactivate()
- */
- @Override
- public void deactivate() {
- if (isHoverActive()) {
- resetHover();
- }
- eraseTargetFeedback();
- targetEditPart = null;
- targetRequest = null;
- setAutoexposeHelper(null);
- super.deactivate();
- }
-
- /**
- * Called to perform an iteration of the autoexpose process. If the expose
- * helper is set, it will be asked to step at the current mouse location. If
- * it returns true, another expose iteration will be queued. There is no
- * delay between autoexpose events, other than the time required to perform
- * the step().
- */
- protected void doAutoexpose() {
- if (exposeHelper == null) {
- return;
- }
- if (exposeHelper.step(getLocation())) {
- handleAutoexpose();
- Display.getCurrent().asyncExec(new QueuedAutoexpose());
- } else {
- setAutoexposeHelper(null);
- }
- }
-
- /**
- * Asks the current target editpart to erase target feedback using the
- * target request. If target feedback is not being shown, this method does
- * nothing and returns. Otherwise, the target feedback flag is reset to
- * false, and the target editpart is asked to erase target feedback. This
- * methods should rarely be overridden.
- */
- protected void eraseTargetFeedback() {
- if (!isShowingTargetFeedback()) {
- return;
- }
- setFlag(FLAG_TARGET_FEEDBACK, false);
- if (getTargetEditPart() != null) {
- getTargetEditPart().eraseTargetFeedback(getTargetRequest());
- }
- }
-
- /**
- * Queries the target editpart for a command.
- *
- * @see org.eclipse.gef.tools.AbstractTool#getCommand()
- */
- @Override
- protected Command getCommand() {
- if (getTargetEditPart() == null) {
- return null;
- }
- return getTargetEditPart().getCommand(getTargetRequest());
- }
-
- /**
- * Returns a List of objects that should be excluded as potential targets
- * for the operation.
- *
- * @return the list of objects to be excluded as targets
- */
- protected Collection getExclusionSet() {
- return Collections.EMPTY_LIST;
- }
-
- /**
- * Returns the conditional object used for obtaining the target editpart
- * from the current viewer. By default, a conditional is returned that tests
- * whether an editpart at the current mouse location indicates a target for
- * the operation's request, using {@link EditPart#getTargetEditPart(Request)}. If <code>null</code> is
- * returned, then the conditional fails, and the search continues.
- *
- * @see EditPartViewer#findObjectAtExcluding(Point, Collection, EditPartViewer.Conditional)
- * @return the targeting conditional
- */
- protected EditPartViewer.Conditional getTargetingConditional() {
- return new EditPartViewer.Conditional() {
-
- @Override
- public boolean evaluate(EditPart editpart) {
- return editpart.getTargetEditPart(getTargetRequest()) != null;
- }
- };
- }
-
- /**
- * Returns <code>null</code> or the current target editpart.
- *
- * @return <code>null</code> or a target part
- */
- protected EditPart getTargetEditPart() {
- return targetEditPart;
- }
-
- /**
- * Lazily creates and returns the request used when communicating with the
- * target editpart.
- *
- * @return the target request
- */
- protected Request getTargetRequest() {
- if (targetRequest == null) {
- setTargetRequest(createTargetRequest());
- }
- return targetRequest;
- }
-
- /**
- * This method is called whenever an autoexpose occurs. When an autoexpose
- * occurs, it is possible that everything in the viewer has moved a little.
- * Therefore, by default, {@link AbstractTool#handleMove() handleMove()} is
- * called to simulate the mouse moving even though it didn't.
- */
- protected void handleAutoexpose() {
- handleMove();
- }
-
- /**
- * Called whenever the target editpart has changed. By default, the target
- * request is updated, and the new target is asked to show feedback.
- * Subclasses may extend this method if needed.
- *
- * @return <code>true</code>
- */
- protected boolean handleEnteredEditPart() {
- updateTargetRequest();
- showTargetFeedback();
- return true;
- }
-
- /**
- * Called whenever the target editpart is about to change. By default, hover
- * is reset, in the case that a hover was showing something, and the target
- * being exited is asked to erase its feedback.
- *
- * @return <code>true</code>
- */
- protected boolean handleExitingEditPart() {
- resetHover();
- eraseTargetFeedback();
- return true;
- }
-
- /**
- * Called from resetHover() iff hover is active. Subclasses may extend this
- * method to handle the hover stop event. Returns <code>true</code> if
- * something was done in response to the call.
- *
- * @see AbstractTool#isHoverActive()
- * @return <code>true</code> if the hover stop is processed in some way
- */
- protected boolean handleHoverStop() {
- return false;
- }
-
- /**
- * Called when invalid input is encountered. By default, feedback is erased,
- * and the current command is set to the unexecutable command. The state
- * does not change, so the caller must set the state to {@link AbstractTool#STATE_INVALID}.
- *
- * @return <code>true</code>
- */
- @Override
- protected boolean handleInvalidInput() {
- eraseTargetFeedback();
- setCurrentCommand(UnexecutableCommand.INSTANCE);
- return true;
- }
-
- /**
- * An archaic method name that has been left here to force use of the new
- * name.
- *
- * @throws Exception
- * exc
- */
- protected final void handleLeavingEditPart() throws Exception {
- }
-
- /**
- * Sets the target to <code>null</code>.
- *
- * @see org.eclipse.gef.tools.AbstractTool#handleViewerExited()
- */
- @Override
- protected boolean handleViewerExited() {
- setTargetEditPart(null);
- return true;
- }
-
- /**
- * Returns <code>true</code> if target feedback is being shown.
- *
- * @return <code>true</code> if showing target feedback
- */
- protected boolean isShowingTargetFeedback() {
- return getFlag(FLAG_TARGET_FEEDBACK);
- }
-
- /**
- * Return <code>true</code> if the current target is locked.
- *
- * @see #lockTargetEditPart(EditPart)
- * @return <code>true</code> if the target is locked
- */
- protected boolean isTargetLocked() {
- return getFlag(FLAG_LOCK_TARGET);
- }
-
- /**
- * Locks-in the given editpart as the target. Updating of the target will
- * not occur until {@link #unlockTargetEditPart()} is called.
- *
- * @param editpart
- * the target to be locked-in
- */
- protected void lockTargetEditPart(EditPart editpart) {
- if (editpart == null) {
- unlockTargetEditPart();
- return;
- }
- setFlag(FLAG_LOCK_TARGET, true);
- setTargetEditPart(editpart);
- }
-
- /**
- * Extended to reset the target lock flag.
- *
- * @see org.eclipse.gef.tools.AbstractTool#resetFlags()
- * @see #lockTargetEditPart(EditPart)
- */
- @Override
- protected void resetFlags() {
- setFlag(FLAG_LOCK_TARGET, false);
- super.resetFlags();
- }
-
- /**
- * Resets hovering to inactive.
- *
- * @since 3.4
- */
- protected void resetHover() {
- if (isHoverActive()) {
- handleHoverStop();
- }
- setHoverActive(false);
- }
-
- class QueuedAutoexpose implements Runnable {
-
- @Override
- public void run() {
- if (exposeHelper != null) {
- doAutoexpose();
- }
- }
- }
-
- /**
- * Sets the active autoexpose helper to the given helper, or <code>null</code>. If the helper is not <code>null</code>, a runnable is
- * queued on the event thread that will trigger a subsequent {@link #doAutoexpose()}. The helper is typically updated only on a hover
- * event.
- *
- * @param helper
- * the new autoexpose helper or <code>null</code>
- */
- protected void setAutoexposeHelper(AutoexposeHelper helper) {
- exposeHelper = helper;
- if (exposeHelper == null) {
- return;
- }
- Display.getCurrent().asyncExec(new QueuedAutoexpose());
- }
-
- /**
- * Sets the target editpart. If the target editpart is changing, this method
- * will call {@link #handleExitingEditPart()} for the previous target if not <code>null</code>, and {@link #handleEnteredEditPart()} for the new
- * target, if not <code>null</code>.
- *
- * @param editpart
- * the new target
- */
- protected void setTargetEditPart(EditPart editpart) {
- if (editpart != targetEditPart) {
- if (targetEditPart != null) {
- handleExitingEditPart();
- }
- targetEditPart = editpart;
- if (getTargetRequest() instanceof TargetRequest) {
- ((TargetRequest) getTargetRequest()).setTargetEditPart(targetEditPart);
- }
- handleEnteredEditPart();
- }
- }
-
- /**
- * Sets the target request. This method is typically not called; subclasses
- * normally override {@link #createTargetRequest()}.
- *
- * @param req
- * the target request
- */
- protected void setTargetRequest(Request req) {
- targetRequest = req;
- }
-
- /**
- * Asks the target editpart to show target feedback and sets the target
- * feedback flag.
- */
- protected void showTargetFeedback() {
- if (getTargetEditPart() != null) {
- getTargetEditPart().showTargetFeedback(getTargetRequest());
- }
- setFlag(FLAG_TARGET_FEEDBACK, true);
- }
-
- /**
- * Releases the targeting lock, and updates the target in case the mouse is
- * already over a new target.
- */
- protected void unlockTargetEditPart() {
- setFlag(FLAG_LOCK_TARGET, false);
- updateTargetUnderMouse();
- }
-
- /**
- * Updates the active {@link AutoexposeHelper}. Does nothing if there is
- * still an active helper. Otherwise, obtains a new helper (possible <code>null</code>) at the current mouse location and calls {@link #setAutoexposeHelper(AutoexposeHelper)}.
- */
- protected void updateAutoexposeHelper() {
- if (exposeHelper != null) {
- return;
- }
- AutoexposeHelper.Search search;
- search = new AutoexposeHelper.Search(getLocation());
- getCurrentViewer().findObjectAtExcluding(getLocation(), Collections.EMPTY_LIST, search);
- setAutoexposeHelper(search.result);
- }
-
- /**
- * Subclasses should override to update the target request.
- */
- protected void updateTargetRequest() {
- }
-
- /**
- * Updates the target editpart and returns <code>true</code> if the target
- * changes. The target is updated by using the target conditional and the
- * target request. If the target has been locked, this method does nothing
- * and returns <code>false</code>.
- *
- * @return <code>true</code> if the target was changed
- */
- protected boolean updateTargetUnderMouse() {
- if (!isTargetLocked()) {
- EditPart editPart = null;
- if (getCurrentViewer() != null) {
- editPart = getCurrentViewer().findObjectAtExcluding(getLocation(), getExclusionSet(), getTargetingConditional());
- }
- if (editPart != null) {
- editPart = editPart.getTargetEditPart(getTargetRequest());
- }
- boolean changed = getTargetEditPart() != editPart;
- setTargetEditPart(editPart);
- return changed;
- } else {
- return false;
- }
- }
-
- /**
- * Returns <code>null</code> or the current autoexpose helper.
- *
- * @return null or a helper
- */
- protected AutoexposeHelper getAutoexposeHelper() {
- return exposeHelper;
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2000, 2010 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.papyrus.infra.gmfdiag.common.snap.copy;
+
+import java.util.Collection;
+import java.util.Collections;
+
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.gef.AutoexposeHelper;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gef.commands.UnexecutableCommand;
+import org.eclipse.gef.requests.TargetRequest;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * The base implementation for tools which perform targeting of editparts.
+ * Targeting tools may operate using either mouse drags or just mouse moves.
+ * Targeting tools work with a <i>target</i> request. This request is used along
+ * with the mouse location to obtain an active target from the current
+ * EditPartViewer. This target is then asked for the <code>Command</code> that
+ * performs the given request. The target is also asked to show target feedback.
+ * <P>
+ * TargetingTool also provides support for auto-expose (a.k.a. auto-scrolling). Subclasses that wish to commence auto-expose can do so by calling {@link #updateAutoexposeHelper()}. An an AutoExposeHelper is found, auto-scrolling begins. Whenever that helper
+ * scrolls the diagram of performs any other change, <code>handleMove</code> will be called as if the mouse had moved. This is because the target has probably moved, but there is no input event to trigger an update of the operation.
+ */
+public abstract class TargetingTool extends AbstractTool {
+
+ private static final int FLAG_LOCK_TARGET = AbstractTool.MAX_FLAG << 1;
+
+ private static final int FLAG_TARGET_FEEDBACK = AbstractTool.MAX_FLAG << 2;
+
+ /**
+ * The max flag.
+ */
+ protected static final int MAX_FLAG = FLAG_TARGET_FEEDBACK;
+
+ private Request targetRequest;
+
+ private EditPart targetEditPart;
+
+ private AutoexposeHelper exposeHelper;
+
+ /**
+ * Creates the target request that will be used with the target editpart.
+ * This request will be cached and updated as needed.
+ *
+ * @see #getTargetRequest()
+ * @return the new target request
+ */
+ protected Request createTargetRequest() {
+ Request request = new Request();
+ request.setType(getCommandName());
+ return request;
+ }
+
+ /**
+ * @see org.eclipse.gef.Tool#deactivate()
+ */
+ @Override
+ public void deactivate() {
+ if (isHoverActive()) {
+ resetHover();
+ }
+ eraseTargetFeedback();
+ targetEditPart = null;
+ targetRequest = null;
+ setAutoexposeHelper(null);
+ super.deactivate();
+ }
+
+ /**
+ * Called to perform an iteration of the autoexpose process. If the expose
+ * helper is set, it will be asked to step at the current mouse location. If
+ * it returns true, another expose iteration will be queued. There is no
+ * delay between autoexpose events, other than the time required to perform
+ * the step().
+ */
+ protected void doAutoexpose() {
+ if (exposeHelper == null) {
+ return;
+ }
+ if (exposeHelper.step(getLocation())) {
+ handleAutoexpose();
+ Display.getCurrent().asyncExec(new QueuedAutoexpose());
+ } else {
+ setAutoexposeHelper(null);
+ }
+ }
+
+ /**
+ * Asks the current target editpart to erase target feedback using the
+ * target request. If target feedback is not being shown, this method does
+ * nothing and returns. Otherwise, the target feedback flag is reset to
+ * false, and the target editpart is asked to erase target feedback. This
+ * methods should rarely be overridden.
+ */
+ protected void eraseTargetFeedback() {
+ if (!isShowingTargetFeedback()) {
+ return;
+ }
+ setFlag(FLAG_TARGET_FEEDBACK, false);
+ if (getTargetEditPart() != null) {
+ getTargetEditPart().eraseTargetFeedback(getTargetRequest());
+ }
+ }
+
+ /**
+ * Queries the target editpart for a command.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#getCommand()
+ */
+ @Override
+ protected Command getCommand() {
+ if (getTargetEditPart() == null) {
+ return null;
+ }
+ return getTargetEditPart().getCommand(getTargetRequest());
+ }
+
+ /**
+ * Returns a List of objects that should be excluded as potential targets
+ * for the operation.
+ *
+ * @return the list of objects to be excluded as targets
+ */
+ protected Collection getExclusionSet() {
+ return Collections.EMPTY_LIST;
+ }
+
+ /**
+ * Returns the conditional object used for obtaining the target editpart
+ * from the current viewer. By default, a conditional is returned that tests
+ * whether an editpart at the current mouse location indicates a target for
+ * the operation's request, using {@link EditPart#getTargetEditPart(Request)}. If <code>null</code> is
+ * returned, then the conditional fails, and the search continues.
+ *
+ * @see EditPartViewer#findObjectAtExcluding(Point, Collection, EditPartViewer.Conditional)
+ * @return the targeting conditional
+ */
+ protected EditPartViewer.Conditional getTargetingConditional() {
+ return new EditPartViewer.Conditional() {
+
+ @Override
+ public boolean evaluate(EditPart editpart) {
+ return editpart.getTargetEditPart(getTargetRequest()) != null;
+ }
+ };
+ }
+
+ /**
+ * Returns <code>null</code> or the current target editpart.
+ *
+ * @return <code>null</code> or a target part
+ */
+ protected EditPart getTargetEditPart() {
+ return targetEditPart;
+ }
+
+ /**
+ * Lazily creates and returns the request used when communicating with the
+ * target editpart.
+ *
+ * @return the target request
+ */
+ protected Request getTargetRequest() {
+ if (targetRequest == null) {
+ setTargetRequest(createTargetRequest());
+ }
+ return targetRequest;
+ }
+
+ /**
+ * This method is called whenever an autoexpose occurs. When an autoexpose
+ * occurs, it is possible that everything in the viewer has moved a little.
+ * Therefore, by default, {@link AbstractTool#handleMove() handleMove()} is
+ * called to simulate the mouse moving even though it didn't.
+ */
+ protected void handleAutoexpose() {
+ handleMove();
+ }
+
+ /**
+ * Called whenever the target editpart has changed. By default, the target
+ * request is updated, and the new target is asked to show feedback.
+ * Subclasses may extend this method if needed.
+ *
+ * @return <code>true</code>
+ */
+ protected boolean handleEnteredEditPart() {
+ updateTargetRequest();
+ showTargetFeedback();
+ return true;
+ }
+
+ /**
+ * Called whenever the target editpart is about to change. By default, hover
+ * is reset, in the case that a hover was showing something, and the target
+ * being exited is asked to erase its feedback.
+ *
+ * @return <code>true</code>
+ */
+ protected boolean handleExitingEditPart() {
+ resetHover();
+ eraseTargetFeedback();
+ return true;
+ }
+
+ /**
+ * Called from resetHover() iff hover is active. Subclasses may extend this
+ * method to handle the hover stop event. Returns <code>true</code> if
+ * something was done in response to the call.
+ *
+ * @see AbstractTool#isHoverActive()
+ * @return <code>true</code> if the hover stop is processed in some way
+ */
+ protected boolean handleHoverStop() {
+ return false;
+ }
+
+ /**
+ * Called when invalid input is encountered. By default, feedback is erased,
+ * and the current command is set to the unexecutable command. The state
+ * does not change, so the caller must set the state to {@link AbstractTool#STATE_INVALID}.
+ *
+ * @return <code>true</code>
+ */
+ @Override
+ protected boolean handleInvalidInput() {
+ eraseTargetFeedback();
+ setCurrentCommand(UnexecutableCommand.INSTANCE);
+ return true;
+ }
+
+ /**
+ * An archaic method name that has been left here to force use of the new
+ * name.
+ *
+ * @throws Exception
+ * exc
+ */
+ protected final void handleLeavingEditPart() throws Exception {
+ }
+
+ /**
+ * Sets the target to <code>null</code>.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#handleViewerExited()
+ */
+ @Override
+ protected boolean handleViewerExited() {
+ setTargetEditPart(null);
+ return true;
+ }
+
+ /**
+ * Returns <code>true</code> if target feedback is being shown.
+ *
+ * @return <code>true</code> if showing target feedback
+ */
+ protected boolean isShowingTargetFeedback() {
+ return getFlag(FLAG_TARGET_FEEDBACK);
+ }
+
+ /**
+ * Return <code>true</code> if the current target is locked.
+ *
+ * @see #lockTargetEditPart(EditPart)
+ * @return <code>true</code> if the target is locked
+ */
+ protected boolean isTargetLocked() {
+ return getFlag(FLAG_LOCK_TARGET);
+ }
+
+ /**
+ * Locks-in the given editpart as the target. Updating of the target will
+ * not occur until {@link #unlockTargetEditPart()} is called.
+ *
+ * @param editpart
+ * the target to be locked-in
+ */
+ protected void lockTargetEditPart(EditPart editpart) {
+ if (editpart == null) {
+ unlockTargetEditPart();
+ return;
+ }
+ setFlag(FLAG_LOCK_TARGET, true);
+ setTargetEditPart(editpart);
+ }
+
+ /**
+ * Extended to reset the target lock flag.
+ *
+ * @see org.eclipse.gef.tools.AbstractTool#resetFlags()
+ * @see #lockTargetEditPart(EditPart)
+ */
+ @Override
+ protected void resetFlags() {
+ setFlag(FLAG_LOCK_TARGET, false);
+ super.resetFlags();
+ }
+
+ /**
+ * Resets hovering to inactive.
+ *
+ * @since 3.4
+ */
+ protected void resetHover() {
+ if (isHoverActive()) {
+ handleHoverStop();
+ }
+ setHoverActive(false);
+ }
+
+ class QueuedAutoexpose implements Runnable {
+
+ @Override
+ public void run() {
+ if (exposeHelper != null) {
+ doAutoexpose();
+ }
+ }
+ }
+
+ /**
+ * Sets the active autoexpose helper to the given helper, or <code>null</code>. If the helper is not <code>null</code>, a runnable is
+ * queued on the event thread that will trigger a subsequent {@link #doAutoexpose()}. The helper is typically updated only on a hover
+ * event.
+ *
+ * @param helper
+ * the new autoexpose helper or <code>null</code>
+ */
+ protected void setAutoexposeHelper(AutoexposeHelper helper) {
+ exposeHelper = helper;
+ if (exposeHelper == null) {
+ return;
+ }
+ Display.getCurrent().asyncExec(new QueuedAutoexpose());
+ }
+
+ /**
+ * Sets the target editpart. If the target editpart is changing, this method
+ * will call {@link #handleExitingEditPart()} for the previous target if not <code>null</code>, and {@link #handleEnteredEditPart()} for the new
+ * target, if not <code>null</code>.
+ *
+ * @param editpart
+ * the new target
+ */
+ protected void setTargetEditPart(EditPart editpart) {
+ if (editpart != targetEditPart) {
+ if (targetEditPart != null) {
+ handleExitingEditPart();
+ }
+ targetEditPart = editpart;
+ if (getTargetRequest() instanceof TargetRequest) {
+ ((TargetRequest) getTargetRequest()).setTargetEditPart(targetEditPart);
+ }
+ handleEnteredEditPart();
+ }
+ }
+
+ /**
+ * Sets the target request. This method is typically not called; subclasses
+ * normally override {@link #createTargetRequest()}.
+ *
+ * @param req
+ * the target request
+ */
+ protected void setTargetRequest(Request req) {
+ targetRequest = req;
+ }
+
+ /**
+ * Asks the target editpart to show target feedback and sets the target
+ * feedback flag.
+ */
+ protected void showTargetFeedback() {
+ if (getTargetEditPart() != null) {
+ getTargetEditPart().showTargetFeedback(getTargetRequest());
+ }
+ setFlag(FLAG_TARGET_FEEDBACK, true);
+ }
+
+ /**
+ * Releases the targeting lock, and updates the target in case the mouse is
+ * already over a new target.
+ */
+ protected void unlockTargetEditPart() {
+ setFlag(FLAG_LOCK_TARGET, false);
+ updateTargetUnderMouse();
+ }
+
+ /**
+ * Updates the active {@link AutoexposeHelper}. Does nothing if there is
+ * still an active helper. Otherwise, obtains a new helper (possible <code>null</code>) at the current mouse location and calls {@link #setAutoexposeHelper(AutoexposeHelper)}.
+ */
+ protected void updateAutoexposeHelper() {
+ if (exposeHelper != null) {
+ return;
+ }
+ AutoexposeHelper.Search search;
+ search = new AutoexposeHelper.Search(getLocation());
+ getCurrentViewer().findObjectAtExcluding(getLocation(), Collections.EMPTY_LIST, search);
+ setAutoexposeHelper(search.result);
+ }
+
+ /**
+ * Subclasses should override to update the target request.
+ */
+ protected void updateTargetRequest() {
+ }
+
+ /**
+ * Updates the target editpart and returns <code>true</code> if the target
+ * changes. The target is updated by using the target conditional and the
+ * target request. If the target has been locked, this method does nothing
+ * and returns <code>false</code>.
+ *
+ * @return <code>true</code> if the target was changed
+ */
+ protected boolean updateTargetUnderMouse() {
+ if (!isTargetLocked()) {
+ EditPart editPart = null;
+ if (getCurrentViewer() != null) {
+ editPart = getCurrentViewer().findObjectAtExcluding(getLocation(), getExclusionSet(), getTargetingConditional());
+ }
+ if (editPart != null) {
+ editPart = editPart.getTargetEditPart(getTargetRequest());
+ }
+ boolean changed = getTargetEditPart() != editPart;
+ setTargetEditPart(editPart);
+ return changed;
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Returns <code>null</code> or the current autoexpose helper.
+ *
+ * @return null or a helper
+ */
+ protected AutoexposeHelper getAutoexposeHelper() {
+ return exposeHelper;
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/copy/AbstractCopyStrategy.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/copy/AbstractCopyStrategy.java
index a0904c356ba..a8407f8fc1c 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/copy/AbstractCopyStrategy.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/strategy/copy/AbstractCopyStrategy.java
@@ -1,102 +1,102 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.Request;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.swt.graphics.Image;
-
-/**
- * Abstract Class for the Copy Strategy, implement ICopyStrategy
- *
- * @author Céline JANSSENS
- *
- */
-public abstract class AbstractCopyStrategy implements ICopyStrategy {
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getLabel()
- *
- * @return the Label
- */
- @Override
- public String getLabel() {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getDescription()
- *
- * @return the Description
- */
- @Override
- public String getDescription() {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getImage()
- *
- * @return the Image
- */
- @Override
- public Image getImage() {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getID()
- *
- * @return the Id
- */
- @Override
- public String getID() {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart)
- */
- @Override
- public Command getCommand(Request request, EditPart targetEditPart) {
- return null;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getPriority()
- *
- * @return
- * @deprecated
- */
- @Deprecated
- @Override
- public int getPriority() {
- return 0;
- }
-
- /**
- * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#prepareElementsInClipboard(java.util.List, java.util.Collection)
- */
- @Override
- public void prepareElementsInClipboard(List<EObject> elementsInClipboard, Collection<EObject> selectedElements) {
- // By default do nothing
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.Request;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * Abstract Class for the Copy Strategy, implement ICopyStrategy
+ *
+ * @author Céline JANSSENS
+ *
+ */
+public abstract class AbstractCopyStrategy implements ICopyStrategy {
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getLabel()
+ *
+ * @return the Label
+ */
+ @Override
+ public String getLabel() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getDescription()
+ *
+ * @return the Description
+ */
+ @Override
+ public String getDescription() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getImage()
+ *
+ * @return the Image
+ */
+ @Override
+ public Image getImage() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getID()
+ *
+ * @return the Id
+ */
+ @Override
+ public String getID() {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getCommand(org.eclipse.gef.Request, org.eclipse.gef.EditPart)
+ */
+ @Override
+ public Command getCommand(Request request, EditPart targetEditPart) {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#getPriority()
+ *
+ * @return
+ * @deprecated
+ */
+ @Deprecated
+ @Override
+ public int getPriority() {
+ return 0;
+ }
+
+ /**
+ * @see org.eclipse.papyrus.infra.gmfdiag.common.strategy.copy.ICopyStrategy#prepareElementsInClipboard(java.util.List, java.util.Collection)
+ */
+ @Override
+ public void prepareElementsInClipboard(List<EObject> elementsInClipboard, Collection<EObject> selectedElements) {
+ // By default do nothing
+
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/EditPartSyncTrigger.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/EditPartSyncTrigger.java
index 970c1c1760b..fe2281ef1a3 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/EditPartSyncTrigger.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/EditPartSyncTrigger.java
@@ -1,127 +1,127 @@
-/*****************************************************************************
- * Copyright (c) 2015 Christian W. Damus 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:
- * Christian W. Damus - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.sync;
-
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.transaction.RollbackException;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.emf.transaction.util.TransactionUtil;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
-import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.sync.SyncBucket;
-import org.eclipse.papyrus.infra.sync.SyncRegistry;
-import org.eclipse.papyrus.infra.sync.service.AbstractSyncTrigger;
-import org.eclipse.papyrus.infra.sync.service.ISyncAction;
-import org.eclipse.papyrus.infra.sync.service.ISyncService;
-
-/**
- * Trigger to engage synchronization on edit parts that have the master/slave synchronization styles set.
- */
-public abstract class EditPartSyncTrigger<M extends EObject, T extends EditPart, X> extends AbstractSyncTrigger {
-
- private final Class<? extends SyncRegistry<M, T, X>> registryType;
-
- public EditPartSyncTrigger(Class<? extends SyncRegistry<M, T, X>> registryType) {
- super();
-
- this.registryType = registryType;
- }
-
- @Override
- public ISyncAction trigger(ISyncService syncService, Object object) {
- ISyncAction result = null;
-
- if (object instanceof EditPart) {
- EditPart editPart = (EditPart) object;
- Object model = editPart.getModel();
- if (model instanceof View) {
- SyncKind kind = SyncStyles.getSyncKind((View) model);
- result = trigger(kind);
- }
- }
-
- return result;
- }
-
- protected ISyncAction trigger(final SyncKind syncKind) {
- return new ISyncAction() {
-
- @Override
- public IStatus perform(final ISyncService syncService, Object object) {
- final IStatus[] result = { Status.OK_STATUS };
- final EditPart editPart = (EditPart) object;
- final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain((View) editPart.getModel());
-
- try {
- GMFUnsafe.write(domain, new Runnable() {
-
- @Override
- public void run() {
- result[0] = doTrigger(syncService, editPart, syncKind);
- }
- });
- } catch (InterruptedException e) {
- result[0] = new Status(IStatus.ERROR, Activator.ID, "Synchronization trigger was interrupted", e);
- } catch (RollbackException e) {
- result[0] = e.getStatus();
- }
-
- return result[0];
- }
- };
- }
-
- protected IStatus doTrigger(ISyncService syncService, EditPart editPart, SyncKind syncKind) {
- IStatus result = Status.OK_STATUS;
-
- SyncRegistry<M, T, X> registry = null;
- M model = null;
- T backend = null;
-
- try {
- registry = syncService.getSyncRegistry(registryType);
- model = AdapterUtils.adapt(editPart, registry.getModelType(), null);
- backend = registry.getBackendType().cast(editPart);
- } catch (Exception e) {
- result = new Status(IStatus.ERROR, Activator.ID, "Failed to access synchronization registry", e);
- }
-
- if ((registry != null) && (model != null)) {
- switch (syncKind) {
- case MASTER:
- SyncBucket<M, T, X> bucket = registry.getBucket(model);
- if (bucket == null) {
- bucket = createSyncBucket(model, backend);
- registry.register(bucket);
- }
- break;
- case SLAVE:
- registry.synchronize(backend);
- break;
- default:
- result = new Status(IStatus.ERROR, Activator.ID, "Unsupported synchronization kind: " + syncKind, null);
- break;
- }
- }
-
- return result;
- }
-
- protected abstract SyncBucket<M, T, X> createSyncBucket(M model, T editPart);
-}
+/*****************************************************************************
+ * Copyright (c) 2015 Christian W. Damus 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:
+ * Christian W. Damus - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.sync;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.transaction.RollbackException;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.emf.transaction.util.TransactionUtil;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.core.utils.AdapterUtils;
+import org.eclipse.papyrus.infra.emf.gmf.util.GMFUnsafe;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.sync.SyncBucket;
+import org.eclipse.papyrus.infra.sync.SyncRegistry;
+import org.eclipse.papyrus.infra.sync.service.AbstractSyncTrigger;
+import org.eclipse.papyrus.infra.sync.service.ISyncAction;
+import org.eclipse.papyrus.infra.sync.service.ISyncService;
+
+/**
+ * Trigger to engage synchronization on edit parts that have the master/slave synchronization styles set.
+ */
+public abstract class EditPartSyncTrigger<M extends EObject, T extends EditPart, X> extends AbstractSyncTrigger {
+
+ private final Class<? extends SyncRegistry<M, T, X>> registryType;
+
+ public EditPartSyncTrigger(Class<? extends SyncRegistry<M, T, X>> registryType) {
+ super();
+
+ this.registryType = registryType;
+ }
+
+ @Override
+ public ISyncAction trigger(ISyncService syncService, Object object) {
+ ISyncAction result = null;
+
+ if (object instanceof EditPart) {
+ EditPart editPart = (EditPart) object;
+ Object model = editPart.getModel();
+ if (model instanceof View) {
+ SyncKind kind = SyncStyles.getSyncKind((View) model);
+ result = trigger(kind);
+ }
+ }
+
+ return result;
+ }
+
+ protected ISyncAction trigger(final SyncKind syncKind) {
+ return new ISyncAction() {
+
+ @Override
+ public IStatus perform(final ISyncService syncService, Object object) {
+ final IStatus[] result = { Status.OK_STATUS };
+ final EditPart editPart = (EditPart) object;
+ final TransactionalEditingDomain domain = TransactionUtil.getEditingDomain((View) editPart.getModel());
+
+ try {
+ GMFUnsafe.write(domain, new Runnable() {
+
+ @Override
+ public void run() {
+ result[0] = doTrigger(syncService, editPart, syncKind);
+ }
+ });
+ } catch (InterruptedException e) {
+ result[0] = new Status(IStatus.ERROR, Activator.ID, "Synchronization trigger was interrupted", e);
+ } catch (RollbackException e) {
+ result[0] = e.getStatus();
+ }
+
+ return result[0];
+ }
+ };
+ }
+
+ protected IStatus doTrigger(ISyncService syncService, EditPart editPart, SyncKind syncKind) {
+ IStatus result = Status.OK_STATUS;
+
+ SyncRegistry<M, T, X> registry = null;
+ M model = null;
+ T backend = null;
+
+ try {
+ registry = syncService.getSyncRegistry(registryType);
+ model = AdapterUtils.adapt(editPart, registry.getModelType(), null);
+ backend = registry.getBackendType().cast(editPart);
+ } catch (Exception e) {
+ result = new Status(IStatus.ERROR, Activator.ID, "Failed to access synchronization registry", e);
+ }
+
+ if ((registry != null) && (model != null)) {
+ switch (syncKind) {
+ case MASTER:
+ SyncBucket<M, T, X> bucket = registry.getBucket(model);
+ if (bucket == null) {
+ bucket = createSyncBucket(model, backend);
+ registry.register(bucket);
+ }
+ break;
+ case SLAVE:
+ registry.synchronize(backend);
+ break;
+ default:
+ result = new Status(IStatus.ERROR, Activator.ID, "Unsupported synchronization kind: " + syncKind, null);
+ break;
+ }
+ }
+
+ return result;
+ }
+
+ protected abstract SyncBucket<M, T, X> createSyncBucket(M model, T editPart);
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodePositionSyncFeature.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodePositionSyncFeature.java
index 9a5a178a7bb..fa22c54ed87 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodePositionSyncFeature.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodePositionSyncFeature.java
@@ -1,157 +1,157 @@
-/*****************************************************************************
- * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, 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:
- * CEA LIST - Initial API and implementation
- * Christian W. Damus - bug 465416
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.sync;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.notation.Location;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.sync.EMFDispatch;
-import org.eclipse.papyrus.infra.sync.EMFDispatchManager;
-import org.eclipse.papyrus.infra.sync.SyncBucket;
-import org.eclipse.papyrus.infra.sync.SyncFeature;
-import org.eclipse.papyrus.infra.sync.SyncItem;
-import org.eclipse.papyrus.infra.tools.util.TypeUtils;
-
-/**
- * Represents a synchronization feature for the position of GMF notation nodes
- *
- * @author Laurent Wouters
- *
- * @param <M>
- * The type of the underlying model element common to all synchronized items in a single bucket
- * @param <T>
- * The type of the backend element to synchronize
- */
-public class NodePositionSyncFeature<M extends EObject, T extends EditPart> extends SyncFeature<M, T, Notification> {
- /**
- * Represents a dispatcher for this feature
- *
- * @author Laurent Wouters
- */
- private class Dispatcher extends NodePositionSyncDispatcher<M, T> {
- public Dispatcher(SyncItem<M, T> item) {
- super(item);
- }
-
- @Override
- public void onClear() {
- // clears the parent bucket
- getBucket().clear();
- }
-
- @Override
- protected void onFilteredChange(Notification notification) {
- NodePositionSyncFeature.this.onChange(item, notification);
- }
- }
-
- private EMFDispatchManager<Dispatcher> dispatchMgr = createSingleDispatchManager();
-
- /**
- * Initialized this feature
- *
- * @param bucket
- * The bucket doing the synchronization
- */
- public NodePositionSyncFeature(SyncBucket<M, T, Notification> bucket) {
- super(bucket);
- }
-
- @Override
- public void observe(SyncItem<M, T> item) {
- dispatchMgr.add(item, new Dispatcher(item));
- }
-
- @Override
- public void unobserve(SyncItem<M, T> item) {
- dispatchMgr.remove(item);
- }
-
- @Override
- protected void onClear() {
- dispatchMgr.removeAll();
- }
-
- @Override
- public void synchronize(SyncItem<M, T> from, SyncItem<M, T> to, Notification message) {
- EditPart fromEditPart = from.getBackend();
- EditPart toEditPart = to.getBackend();
-
- // retrieve the locations
- Point locationFrom = getLocation(fromEditPart);
- Point locationTo = getLocation(toEditPart);
-
- if (!locationFrom.equals(locationTo)) {
- // compute the reaction command
- Command reaction = GMFtoEMFCommandWrapper.wrap(new SetBoundsCommand(getEditingDomain(), "Synchronize Node Location", toEditPart, locationFrom));
-
- // dispatch the reaction
- if (message == null) {
- // this is an initial sync request
- execute(reaction);
- } else {
- // this is reaction to a change
- Dispatcher dispatcher = dispatchMgr.getDispatcher(from, message.getFeature());
- if (dispatcher != null) {
- dispatcher.react(reaction);
- }
- }
- }
- }
-
- Point getLocation(EditPart editPart) {
- Point result = null;
-
- Node node = (Node) editPart.getModel();
- Location location = TypeUtils.as(node.getLayoutConstraint(), Location.class);
- if (location != null) {
- result = new Point(location.getX(), location.getY());
- } else {
- IFigure figure = ((GraphicalEditPart) editPart).getFigure();
- result = figure.getBounds().getLocation();
- }
-
- return result;
- }
-
- public static <M extends EObject, T extends EditPart> NotationSyncPolicyDelegate<M, T> createPolicyDelegate() {
- return new NotationSyncPolicyDelegate<M, T>(NotationPackage.Literals.LOCATION.getName()) {
-
- @Override
- protected EMFDispatch createDispatcher(SyncItem<M, T> syncTarget) {
- return new NodePositionSyncDispatcher<M, T>(syncTarget) {
- @Override
- public void onClear() {
- // Nothing to do do
- }
-
- @Override
- protected void onFilteredChange(Notification notification) {
- overrideOccurred(this, getItem());
- }
- };
- }
- };
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, 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:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 465416
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.sync;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
+import org.eclipse.gmf.runtime.notation.Location;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.sync.EMFDispatch;
+import org.eclipse.papyrus.infra.sync.EMFDispatchManager;
+import org.eclipse.papyrus.infra.sync.SyncBucket;
+import org.eclipse.papyrus.infra.sync.SyncFeature;
+import org.eclipse.papyrus.infra.sync.SyncItem;
+import org.eclipse.papyrus.infra.tools.util.TypeUtils;
+
+/**
+ * Represents a synchronization feature for the position of GMF notation nodes
+ *
+ * @author Laurent Wouters
+ *
+ * @param <M>
+ * The type of the underlying model element common to all synchronized items in a single bucket
+ * @param <T>
+ * The type of the backend element to synchronize
+ */
+public class NodePositionSyncFeature<M extends EObject, T extends EditPart> extends SyncFeature<M, T, Notification> {
+ /**
+ * Represents a dispatcher for this feature
+ *
+ * @author Laurent Wouters
+ */
+ private class Dispatcher extends NodePositionSyncDispatcher<M, T> {
+ public Dispatcher(SyncItem<M, T> item) {
+ super(item);
+ }
+
+ @Override
+ public void onClear() {
+ // clears the parent bucket
+ getBucket().clear();
+ }
+
+ @Override
+ protected void onFilteredChange(Notification notification) {
+ NodePositionSyncFeature.this.onChange(item, notification);
+ }
+ }
+
+ private EMFDispatchManager<Dispatcher> dispatchMgr = createSingleDispatchManager();
+
+ /**
+ * Initialized this feature
+ *
+ * @param bucket
+ * The bucket doing the synchronization
+ */
+ public NodePositionSyncFeature(SyncBucket<M, T, Notification> bucket) {
+ super(bucket);
+ }
+
+ @Override
+ public void observe(SyncItem<M, T> item) {
+ dispatchMgr.add(item, new Dispatcher(item));
+ }
+
+ @Override
+ public void unobserve(SyncItem<M, T> item) {
+ dispatchMgr.remove(item);
+ }
+
+ @Override
+ protected void onClear() {
+ dispatchMgr.removeAll();
+ }
+
+ @Override
+ public void synchronize(SyncItem<M, T> from, SyncItem<M, T> to, Notification message) {
+ EditPart fromEditPart = from.getBackend();
+ EditPart toEditPart = to.getBackend();
+
+ // retrieve the locations
+ Point locationFrom = getLocation(fromEditPart);
+ Point locationTo = getLocation(toEditPart);
+
+ if (!locationFrom.equals(locationTo)) {
+ // compute the reaction command
+ Command reaction = GMFtoEMFCommandWrapper.wrap(new SetBoundsCommand(getEditingDomain(), "Synchronize Node Location", toEditPart, locationFrom));
+
+ // dispatch the reaction
+ if (message == null) {
+ // this is an initial sync request
+ execute(reaction);
+ } else {
+ // this is reaction to a change
+ Dispatcher dispatcher = dispatchMgr.getDispatcher(from, message.getFeature());
+ if (dispatcher != null) {
+ dispatcher.react(reaction);
+ }
+ }
+ }
+ }
+
+ Point getLocation(EditPart editPart) {
+ Point result = null;
+
+ Node node = (Node) editPart.getModel();
+ Location location = TypeUtils.as(node.getLayoutConstraint(), Location.class);
+ if (location != null) {
+ result = new Point(location.getX(), location.getY());
+ } else {
+ IFigure figure = ((GraphicalEditPart) editPart).getFigure();
+ result = figure.getBounds().getLocation();
+ }
+
+ return result;
+ }
+
+ public static <M extends EObject, T extends EditPart> NotationSyncPolicyDelegate<M, T> createPolicyDelegate() {
+ return new NotationSyncPolicyDelegate<M, T>(NotationPackage.Literals.LOCATION.getName()) {
+
+ @Override
+ protected EMFDispatch createDispatcher(SyncItem<M, T> syncTarget) {
+ return new NodePositionSyncDispatcher<M, T>(syncTarget) {
+ @Override
+ public void onClear() {
+ // Nothing to do do
+ }
+
+ @Override
+ protected void onFilteredChange(Notification notification) {
+ overrideOccurred(this, getItem());
+ }
+ };
+ }
+ };
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodeSizeSyncFeature.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodeSizeSyncFeature.java
index 25c9f8fb2b8..e527bece744 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodeSizeSyncFeature.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/sync/NodeSizeSyncFeature.java
@@ -1,164 +1,164 @@
-/*****************************************************************************
- * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, 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:
- * CEA LIST - Initial API and implementation
- * Christian W. Damus - bug 465416
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.sync;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Dimension;
-import org.eclipse.emf.common.command.Command;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
-import org.eclipse.gmf.runtime.notation.Node;
-import org.eclipse.gmf.runtime.notation.NotationPackage;
-import org.eclipse.gmf.runtime.notation.Size;
-import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
-import org.eclipse.papyrus.infra.sync.EMFDispatch;
-import org.eclipse.papyrus.infra.sync.EMFDispatchManager;
-import org.eclipse.papyrus.infra.sync.SyncBucket;
-import org.eclipse.papyrus.infra.sync.SyncFeature;
-import org.eclipse.papyrus.infra.sync.SyncItem;
-import org.eclipse.papyrus.infra.tools.util.TypeUtils;
-
-/**
- * Represents a synchronization feature for the position of GMF notation nodes
- *
- * @author Laurent Wouters
- *
- * @param <M>
- * The type of the underlying model element common to all synchronized items in a single bucket
- * @param <T>
- * The type of the backend element to synchronize
- */
-public class NodeSizeSyncFeature<M extends EObject, T extends EditPart> extends SyncFeature<M, T, Notification> {
- /**
- * Represents a dispatcher for this feature
- *
- * @author Laurent Wouters
- */
- private class Dispatcher extends NodeSizeSyncDispatcher<M, T> {
- public Dispatcher(SyncItem<M, T> item) {
- super(item);
- }
-
- @Override
- public void onClear() {
- // clears the parent bucket
- getBucket().clear();
- }
-
- @Override
- protected void onFilteredChange(Notification notification) {
- NodeSizeSyncFeature.this.onChange(item, notification);
- }
- }
-
- /**
- * The active dispatchers
- */
- private EMFDispatchManager<Dispatcher> dispatchMgr = createSingleDispatchManager();
-
- /**
- * Initialized this feature
- *
- * @param bucket
- * The bucket doing the synchronization
- */
- public NodeSizeSyncFeature(SyncBucket<M, T, Notification> bucket) {
- super(bucket);
- }
-
- @Override
- public void observe(SyncItem<M, T> item) {
- dispatchMgr.add(item, new Dispatcher(item));
- }
-
- @Override
- public void unobserve(SyncItem<M, T> item) {
- dispatchMgr.remove(item);
- }
-
- @Override
- protected void onClear() {
- dispatchMgr.removeAll();
- }
-
- @Override
- public void synchronize(SyncItem<M, T> from, SyncItem<M, T> to, Notification message) {
- EditPart fromEditPart = from.getBackend();
- EditPart toEditPart = to.getBackend();
-
- // retrieve the sizes
- Dimension sizeFrom = getSize(fromEditPart);
- Dimension sizeTo = getSize(toEditPart);
-
- if (!sizeFrom.equals(sizeTo)) {
- // compute the reaction command
- Command reaction = GMFtoEMFCommandWrapper.wrap(new SetBoundsCommand(getEditingDomain(), "Synchronize Node Size", toEditPart, sizeFrom));
-
- // dispatch the reaction
- if (message == null) {
- // this is an initial sync request
- execute(reaction);
- } else {
- // this is reaction to a change
- Dispatcher dispatcher = dispatchMgr.getDispatcher(from, message.getFeature());
- if (dispatcher != null) {
- dispatcher.react(reaction);
- }
- }
- }
- }
-
- Dimension getSize(EditPart editPart) {
- Dimension result = null;
-
- Node node = (Node) editPart.getModel();
- Size size = TypeUtils.as(node.getLayoutConstraint(), Size.class);
- if ((size != null) && (size.getWidth() >= 0) && (size.getHeight() >= 0)) {
- // Nice. We have non-default (non-computed) size
- result = new Dimension(size.getWidth(), size.getHeight());
- }
-
- if (result == null) {
- // Need to get the actual dimensions from the edit-part's figure
- IFigure figure = ((GraphicalEditPart) editPart).getFigure();
- result = figure.getBounds().getSize();
- }
-
- return result;
- }
-
- public static <M extends EObject, T extends EditPart> NotationSyncPolicyDelegate<M, T> createPolicyDelegate() {
- return new NotationSyncPolicyDelegate<M, T>(NotationPackage.Literals.SIZE.getName()) {
-
- @Override
- protected EMFDispatch createDispatcher(SyncItem<M, T> syncTarget) {
- return new NodeSizeSyncDispatcher<M, T>(syncTarget) {
- @Override
- public void onClear() {
- // Nothing to do do
- }
-
- @Override
- protected void onFilteredChange(Notification notification) {
- overrideOccurred(this, getItem());
- }
- };
- }
- };
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2014, 2015 CEA LIST, Christian W. Damus, 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:
+ * CEA LIST - Initial API and implementation
+ * Christian W. Damus - bug 465416
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.sync;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Dimension;
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.common.notify.Notification;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.commands.SetBoundsCommand;
+import org.eclipse.gmf.runtime.notation.Node;
+import org.eclipse.gmf.runtime.notation.NotationPackage;
+import org.eclipse.gmf.runtime.notation.Size;
+import org.eclipse.papyrus.infra.emf.gmf.command.GMFtoEMFCommandWrapper;
+import org.eclipse.papyrus.infra.sync.EMFDispatch;
+import org.eclipse.papyrus.infra.sync.EMFDispatchManager;
+import org.eclipse.papyrus.infra.sync.SyncBucket;
+import org.eclipse.papyrus.infra.sync.SyncFeature;
+import org.eclipse.papyrus.infra.sync.SyncItem;
+import org.eclipse.papyrus.infra.tools.util.TypeUtils;
+
+/**
+ * Represents a synchronization feature for the position of GMF notation nodes
+ *
+ * @author Laurent Wouters
+ *
+ * @param <M>
+ * The type of the underlying model element common to all synchronized items in a single bucket
+ * @param <T>
+ * The type of the backend element to synchronize
+ */
+public class NodeSizeSyncFeature<M extends EObject, T extends EditPart> extends SyncFeature<M, T, Notification> {
+ /**
+ * Represents a dispatcher for this feature
+ *
+ * @author Laurent Wouters
+ */
+ private class Dispatcher extends NodeSizeSyncDispatcher<M, T> {
+ public Dispatcher(SyncItem<M, T> item) {
+ super(item);
+ }
+
+ @Override
+ public void onClear() {
+ // clears the parent bucket
+ getBucket().clear();
+ }
+
+ @Override
+ protected void onFilteredChange(Notification notification) {
+ NodeSizeSyncFeature.this.onChange(item, notification);
+ }
+ }
+
+ /**
+ * The active dispatchers
+ */
+ private EMFDispatchManager<Dispatcher> dispatchMgr = createSingleDispatchManager();
+
+ /**
+ * Initialized this feature
+ *
+ * @param bucket
+ * The bucket doing the synchronization
+ */
+ public NodeSizeSyncFeature(SyncBucket<M, T, Notification> bucket) {
+ super(bucket);
+ }
+
+ @Override
+ public void observe(SyncItem<M, T> item) {
+ dispatchMgr.add(item, new Dispatcher(item));
+ }
+
+ @Override
+ public void unobserve(SyncItem<M, T> item) {
+ dispatchMgr.remove(item);
+ }
+
+ @Override
+ protected void onClear() {
+ dispatchMgr.removeAll();
+ }
+
+ @Override
+ public void synchronize(SyncItem<M, T> from, SyncItem<M, T> to, Notification message) {
+ EditPart fromEditPart = from.getBackend();
+ EditPart toEditPart = to.getBackend();
+
+ // retrieve the sizes
+ Dimension sizeFrom = getSize(fromEditPart);
+ Dimension sizeTo = getSize(toEditPart);
+
+ if (!sizeFrom.equals(sizeTo)) {
+ // compute the reaction command
+ Command reaction = GMFtoEMFCommandWrapper.wrap(new SetBoundsCommand(getEditingDomain(), "Synchronize Node Size", toEditPart, sizeFrom));
+
+ // dispatch the reaction
+ if (message == null) {
+ // this is an initial sync request
+ execute(reaction);
+ } else {
+ // this is reaction to a change
+ Dispatcher dispatcher = dispatchMgr.getDispatcher(from, message.getFeature());
+ if (dispatcher != null) {
+ dispatcher.react(reaction);
+ }
+ }
+ }
+ }
+
+ Dimension getSize(EditPart editPart) {
+ Dimension result = null;
+
+ Node node = (Node) editPart.getModel();
+ Size size = TypeUtils.as(node.getLayoutConstraint(), Size.class);
+ if ((size != null) && (size.getWidth() >= 0) && (size.getHeight() >= 0)) {
+ // Nice. We have non-default (non-computed) size
+ result = new Dimension(size.getWidth(), size.getHeight());
+ }
+
+ if (result == null) {
+ // Need to get the actual dimensions from the edit-part's figure
+ IFigure figure = ((GraphicalEditPart) editPart).getFigure();
+ result = figure.getBounds().getSize();
+ }
+
+ return result;
+ }
+
+ public static <M extends EObject, T extends EditPart> NotationSyncPolicyDelegate<M, T> createPolicyDelegate() {
+ return new NotationSyncPolicyDelegate<M, T>(NotationPackage.Literals.SIZE.getName()) {
+
+ @Override
+ protected EMFDispatch createDispatcher(SyncItem<M, T> syncTarget) {
+ return new NodeSizeSyncDispatcher<M, T>(syncTarget) {
+ @Override
+ public void onClear() {
+ // Nothing to do do
+ }
+
+ @Override
+ protected void onFilteredChange(Notification notification) {
+ overrideOccurred(this, getItem());
+ }
+ };
+ }
+ };
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java
index 2d581c5b868..24769b0af22 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/types/NotationTypesMap.java
@@ -1,207 +1,207 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.types;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
-import org.eclipse.papyrus.infra.tools.util.StringHelper;
-
-/**
- * This singleton holds a map between computer-readable notation types (e.g. 7017) and human-readable
- * types (e.g. Attribute Compartment)
- *
- * @author Camille Letavernier
- *
- */
-public class NotationTypesMap {
-
- public static final NotationTypesMap instance = new NotationTypesMap();
-
- public static final String EXTENSION_ID = Activator.ID + ".notationTypesMapping"; //$NON-NLS-1$
-
- public static final String DIAGRAM_CATEGORY = "diagramMappings"; //$NON-NLS-1$
-
- public static final String ALL_DIAGRAMS = "Papyrus.AllDiagrams"; //$NON-NLS-1$
-
- public static final String MAPPING = "mapping";
-
- private final Map<String, TypeMap> typeMaps = new HashMap<String, TypeMap>(); // DiagramID -> TypeMap
-
- private NotationTypesMap() {
- readExtensionPoint();
- }
-
- private void readExtensionPoint() {
- IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
- for (IConfigurationElement diagramMappingsDefinition : configurationElements) {
-
- if (DIAGRAM_CATEGORY.equals(diagramMappingsDefinition.getName())) {
- String diagramID = diagramMappingsDefinition.getAttribute("diagramID");
-
- TypeMap typeMap = getOrCreateTypeMap(diagramID);
-
- for (IConfigurationElement mappingDefinition : diagramMappingsDefinition.getChildren()) {
-
- final String notationType = mappingDefinition.getAttribute("type");
- final String humanReadableType = StringHelper.toJavaIdentifier(mappingDefinition.getAttribute("humanReadableType"));
-
- if (notationType == null || humanReadableType == null) {
- Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", mappingDefinition.getContributor().getName()));
- continue;
- }
-
-
- typeMap.getComputerToHumanTypeMapping().put(notationType, humanReadableType);
- typeMap.getHumanToComputerTypeMapping().put(humanReadableType, notationType);
- }
- } else if (MAPPING.equals(diagramMappingsDefinition.getName())) {
-
- TypeMap typeMap = TypeMap.defaultMap;
-
- final String notationType = diagramMappingsDefinition.getAttribute("type");
- final String humanReadableType = StringHelper.toJavaIdentifier(diagramMappingsDefinition.getAttribute("humanReadableType"));
-
- if (notationType == null || humanReadableType == null) {
- Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", diagramMappingsDefinition.getContributor().getName()));
- continue;
- }
-
-
- typeMap.getComputerToHumanTypeMapping().put(notationType, humanReadableType);
- typeMap.getHumanToComputerTypeMapping().put(humanReadableType, notationType);
- }
- }
- }
-
- // Never null.
- // Used at runtime. Do not fill the map if the diagramID doesn't exist.
- private TypeMap getTypeMap(String diagramID) {
- if (typeMaps.containsKey(diagramID)) {
- return typeMaps.get(diagramID);
- }
-
- return TypeMap.defaultMap;
- }
-
- private TypeMap getTypeMap(View view) {
- if (view.getDiagram() == null) {
- return TypeMap.defaultMap;
- }
-
- return getTypeMap(view.getDiagram().getType());
- }
-
- // Never null.
- // Used during parsing of extension point. Fills the map if the diagramID doesn't exist
- private TypeMap getOrCreateTypeMap(String diagramID) {
- if (!typeMaps.containsKey(diagramID)) {
- TypeMap typeMap = new TypeMap();
- typeMaps.put(diagramID, typeMap);
- }
-
- return typeMaps.get(diagramID);
- }
-
- // ////////////////////
-
- public String getNotationType(String humanReadableType, String diagramID) {
- return getTypeMap(diagramID).getNotationType(humanReadableType);
- }
-
- public String getHumanReadableType(String notationType, String diagramID) {
- return getTypeMap(diagramID).getHumanReadableType(notationType);
- }
-
- public Map<String, String> getComputerToHumanTypeMapping(String diagramID) {
- return getTypeMap(diagramID).getComputerToHumanTypeMapping();
- }
-
- public Map<String, String> getHumanToComputerTypeMapping(String diagramID) {
- return getTypeMap(diagramID).getHumanToComputerTypeMapping();
- }
-
- // ////////////////////
-
- public String getNotationType(View view) {
- if (view == null) {
- return null;
- }
-
- return getTypeMap(view).getNotationType(view.getType());
- }
-
- public String getHumanReadableType(View view) {
- if (view == null) {
- return null;
- }
-
- return getTypeMap(view).getHumanReadableType(view.getType());
- }
-
-
- public Map<String, String> getComputerToHumanTypeMapping(Diagram diagram) {
- if (diagram == null) {
- return TypeMap.defaultMap.getComputerToHumanTypeMapping();
- }
-
- return getComputerToHumanTypeMapping(diagram.getType());
- }
-
- public Map<String, String> getHumanToComputerTypeMapping(Diagram diagram) {
- if (diagram == null) {
- return TypeMap.defaultMap.getHumanToComputerTypeMapping();
- }
-
- return getHumanToComputerTypeMapping(diagram.getType());
- }
-
- // ////////////////////
-
- private static class TypeMap {
-
- public static final TypeMap defaultMap = new TypeMap();
-
- private final Map<String, String> computerToHumanTypeMapping = new HashMap<String, String>(); // GMF Type -> Human-readable Type
-
- private final Map<String, String> humanToComputerTypeMapping = new HashMap<String, String>(); // Human-readable Type -> GMF Type
-
- public String getNotationType(String humanReadableType) {
- if (humanToComputerTypeMapping.containsKey(humanReadableType) || defaultMap == this) {
- return humanToComputerTypeMapping.get(humanReadableType);
- }
-
- return defaultMap.getNotationType(humanReadableType);
- }
-
- public String getHumanReadableType(String notationType) {
- if (computerToHumanTypeMapping.containsKey(notationType) || defaultMap == this) {
- return computerToHumanTypeMapping.get(notationType);
- }
-
- return defaultMap.getHumanReadableType(notationType);
- }
-
- public Map<String, String> getComputerToHumanTypeMapping() {
- return computerToHumanTypeMapping;
- }
-
- public Map<String, String> getHumanToComputerTypeMapping() {
- return humanToComputerTypeMapping;
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.types;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.gmf.runtime.notation.Diagram;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.papyrus.infra.gmfdiag.common.Activator;
+import org.eclipse.papyrus.infra.tools.util.StringHelper;
+
+/**
+ * This singleton holds a map between computer-readable notation types (e.g. 7017) and human-readable
+ * types (e.g. Attribute Compartment)
+ *
+ * @author Camille Letavernier
+ *
+ */
+public class NotationTypesMap {
+
+ public static final NotationTypesMap instance = new NotationTypesMap();
+
+ public static final String EXTENSION_ID = Activator.ID + ".notationTypesMapping"; //$NON-NLS-1$
+
+ public static final String DIAGRAM_CATEGORY = "diagramMappings"; //$NON-NLS-1$
+
+ public static final String ALL_DIAGRAMS = "Papyrus.AllDiagrams"; //$NON-NLS-1$
+
+ public static final String MAPPING = "mapping";
+
+ private final Map<String, TypeMap> typeMaps = new HashMap<String, TypeMap>(); // DiagramID -> TypeMap
+
+ private NotationTypesMap() {
+ readExtensionPoint();
+ }
+
+ private void readExtensionPoint() {
+ IConfigurationElement[] configurationElements = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
+ for (IConfigurationElement diagramMappingsDefinition : configurationElements) {
+
+ if (DIAGRAM_CATEGORY.equals(diagramMappingsDefinition.getName())) {
+ String diagramID = diagramMappingsDefinition.getAttribute("diagramID");
+
+ TypeMap typeMap = getOrCreateTypeMap(diagramID);
+
+ for (IConfigurationElement mappingDefinition : diagramMappingsDefinition.getChildren()) {
+
+ final String notationType = mappingDefinition.getAttribute("type");
+ final String humanReadableType = StringHelper.toJavaIdentifier(mappingDefinition.getAttribute("humanReadableType"));
+
+ if (notationType == null || humanReadableType == null) {
+ Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", mappingDefinition.getContributor().getName()));
+ continue;
+ }
+
+
+ typeMap.getComputerToHumanTypeMapping().put(notationType, humanReadableType);
+ typeMap.getHumanToComputerTypeMapping().put(humanReadableType, notationType);
+ }
+ } else if (MAPPING.equals(diagramMappingsDefinition.getName())) {
+
+ TypeMap typeMap = TypeMap.defaultMap;
+
+ final String notationType = diagramMappingsDefinition.getAttribute("type");
+ final String humanReadableType = StringHelper.toJavaIdentifier(diagramMappingsDefinition.getAttribute("humanReadableType"));
+
+ if (notationType == null || humanReadableType == null) {
+ Activator.log.warn(String.format("Plug-in %s contributed an invalid extension for Notation Type Mappings", diagramMappingsDefinition.getContributor().getName()));
+ continue;
+ }
+
+
+ typeMap.getComputerToHumanTypeMapping().put(notationType, humanReadableType);
+ typeMap.getHumanToComputerTypeMapping().put(humanReadableType, notationType);
+ }
+ }
+ }
+
+ // Never null.
+ // Used at runtime. Do not fill the map if the diagramID doesn't exist.
+ private TypeMap getTypeMap(String diagramID) {
+ if (typeMaps.containsKey(diagramID)) {
+ return typeMaps.get(diagramID);
+ }
+
+ return TypeMap.defaultMap;
+ }
+
+ private TypeMap getTypeMap(View view) {
+ if (view.getDiagram() == null) {
+ return TypeMap.defaultMap;
+ }
+
+ return getTypeMap(view.getDiagram().getType());
+ }
+
+ // Never null.
+ // Used during parsing of extension point. Fills the map if the diagramID doesn't exist
+ private TypeMap getOrCreateTypeMap(String diagramID) {
+ if (!typeMaps.containsKey(diagramID)) {
+ TypeMap typeMap = new TypeMap();
+ typeMaps.put(diagramID, typeMap);
+ }
+
+ return typeMaps.get(diagramID);
+ }
+
+ // ////////////////////
+
+ public String getNotationType(String humanReadableType, String diagramID) {
+ return getTypeMap(diagramID).getNotationType(humanReadableType);
+ }
+
+ public String getHumanReadableType(String notationType, String diagramID) {
+ return getTypeMap(diagramID).getHumanReadableType(notationType);
+ }
+
+ public Map<String, String> getComputerToHumanTypeMapping(String diagramID) {
+ return getTypeMap(diagramID).getComputerToHumanTypeMapping();
+ }
+
+ public Map<String, String> getHumanToComputerTypeMapping(String diagramID) {
+ return getTypeMap(diagramID).getHumanToComputerTypeMapping();
+ }
+
+ // ////////////////////
+
+ public String getNotationType(View view) {
+ if (view == null) {
+ return null;
+ }
+
+ return getTypeMap(view).getNotationType(view.getType());
+ }
+
+ public String getHumanReadableType(View view) {
+ if (view == null) {
+ return null;
+ }
+
+ return getTypeMap(view).getHumanReadableType(view.getType());
+ }
+
+
+ public Map<String, String> getComputerToHumanTypeMapping(Diagram diagram) {
+ if (diagram == null) {
+ return TypeMap.defaultMap.getComputerToHumanTypeMapping();
+ }
+
+ return getComputerToHumanTypeMapping(diagram.getType());
+ }
+
+ public Map<String, String> getHumanToComputerTypeMapping(Diagram diagram) {
+ if (diagram == null) {
+ return TypeMap.defaultMap.getHumanToComputerTypeMapping();
+ }
+
+ return getHumanToComputerTypeMapping(diagram.getType());
+ }
+
+ // ////////////////////
+
+ private static class TypeMap {
+
+ public static final TypeMap defaultMap = new TypeMap();
+
+ private final Map<String, String> computerToHumanTypeMapping = new HashMap<String, String>(); // GMF Type -> Human-readable Type
+
+ private final Map<String, String> humanToComputerTypeMapping = new HashMap<String, String>(); // Human-readable Type -> GMF Type
+
+ public String getNotationType(String humanReadableType) {
+ if (humanToComputerTypeMapping.containsKey(humanReadableType) || defaultMap == this) {
+ return humanToComputerTypeMapping.get(humanReadableType);
+ }
+
+ return defaultMap.getNotationType(humanReadableType);
+ }
+
+ public String getHumanReadableType(String notationType) {
+ if (computerToHumanTypeMapping.containsKey(notationType) || defaultMap == this) {
+ return computerToHumanTypeMapping.get(notationType);
+ }
+
+ return defaultMap.getHumanReadableType(notationType);
+ }
+
+ public Map<String, String> getComputerToHumanTypeMapping() {
+ return computerToHumanTypeMapping;
+ }
+
+ public Map<String, String> getHumanToComputerTypeMapping() {
+ return humanToComputerTypeMapping;
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/undocontext/UndoContextServiceFactory.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/undocontext/UndoContextServiceFactory.java
index 8b75039d1dc..b95bd0cc5e9 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/undocontext/UndoContextServiceFactory.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/undocontext/UndoContextServiceFactory.java
@@ -1,94 +1,94 @@
-/*****************************************************************************
- * Copyright (c) 2012 Cedric Dumoulin.
- *
- *
- * 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:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.undocontext;
-
-import org.eclipse.core.commands.operations.IUndoContext;
-import org.eclipse.emf.transaction.TransactionalEditingDomain;
-import org.eclipse.gmf.runtime.emf.commands.core.command.EditingDomainUndoContext;
-import org.eclipse.papyrus.infra.core.services.IServiceFactory;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
-
-
-/**
- * Service Factory used to create the {@link IUndoContext} used by all editors and views associated to
- * a model (or {@link ServicesRegistry}).
- * The {@link IUndoContext} can be retrieved from the {@link ServicesRegistry}.
- *
- * @author Cedric Dumoulin
- *
- */
-// TODO: Refactor 0.10: To be moved out of infra.core
-public class UndoContextServiceFactory implements IServiceFactory {
-
- /**
- * Undo context used to have the same undo context in all Papyrus related views and editors.
- */
- private IUndoContext undoContext;
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- @Override
- public void init(ServicesRegistry servicesRegistry) throws ServiceException {
-
- // Lookup TransactionalEditingDomain
- TransactionalEditingDomain transactionalEditingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(servicesRegistry);
- // Create the undoContext
- undoContext = new EditingDomainUndoContext(transactionalEditingDomain);
- }
-
- /**
- * Do nothing
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#startService()
- *
- * @throws ServiceException
- */
- @Override
- public void startService() throws ServiceException {
- }
-
- /**
- * Do nothing
- *
- * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
- *
- * @throws ServiceException
- */
- @Override
- public void disposeService() throws ServiceException {
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
- *
- * @return
- * @throws ServiceException
- */
- @Override
- public Object createServiceInstance() throws ServiceException {
- return undoContext;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 Cedric Dumoulin.
+ *
+ *
+ * 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:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.undocontext;
+
+import org.eclipse.core.commands.operations.IUndoContext;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.gmf.runtime.emf.commands.core.command.EditingDomainUndoContext;
+import org.eclipse.papyrus.infra.core.services.IServiceFactory;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.ServiceUtils;
+
+
+/**
+ * Service Factory used to create the {@link IUndoContext} used by all editors and views associated to
+ * a model (or {@link ServicesRegistry}).
+ * The {@link IUndoContext} can be retrieved from the {@link ServicesRegistry}.
+ *
+ * @author Cedric Dumoulin
+ *
+ */
+// TODO: Refactor 0.10: To be moved out of infra.core
+public class UndoContextServiceFactory implements IServiceFactory {
+
+ /**
+ * Undo context used to have the same undo context in all Papyrus related views and editors.
+ */
+ private IUndoContext undoContext;
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#init(org.eclipse.papyrus.infra.core.services.ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @Override
+ public void init(ServicesRegistry servicesRegistry) throws ServiceException {
+
+ // Lookup TransactionalEditingDomain
+ TransactionalEditingDomain transactionalEditingDomain = ServiceUtils.getInstance().getTransactionalEditingDomain(servicesRegistry);
+ // Create the undoContext
+ undoContext = new EditingDomainUndoContext(transactionalEditingDomain);
+ }
+
+ /**
+ * Do nothing
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#startService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void startService() throws ServiceException {
+ }
+
+ /**
+ * Do nothing
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IService#disposeService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void disposeService() throws ServiceException {
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.IServiceFactory#createServiceInstance()
+ *
+ * @return
+ * @throws ServiceException
+ */
+ @Override
+ public Object createServiceInstance() throws ServiceException {
+ return undoContext;
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CommandIds.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CommandIds.java
index c5dc46c3f70..3d523fc2dbd 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CommandIds.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CommandIds.java
@@ -1,32 +1,32 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-
-public class CommandIds {
-
- private CommandIds() {
- // to prevent instanciation
- }
-
- public static final String VIEW_GRID_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.ViewGridCommand"; //$NON-NLS-1$
-
- public static final String VIEW_RULER_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.ViewRulersCommand"; //$NON-NLS-1$
-
- public static final String VIEW_PAGE_BREAK_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.ViewPageBreaksCommand"; //$NON-NLS-1$
-
- public static final String SNAP_TO_GRID_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.SnapToGridCommand"; //$NON-NLS-1$
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+
+public class CommandIds {
+
+ private CommandIds() {
+ // to prevent instanciation
+ }
+
+ public static final String VIEW_GRID_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.ViewGridCommand"; //$NON-NLS-1$
+
+ public static final String VIEW_RULER_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.ViewRulersCommand"; //$NON-NLS-1$
+
+ public static final String VIEW_PAGE_BREAK_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.ViewPageBreaksCommand"; //$NON-NLS-1$
+
+ public static final String SNAP_TO_GRID_COMMAND = "org.eclipse.papyrus.infra.gmfdiag.menu.SnapToGridCommand"; //$NON-NLS-1$
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CopyPasteUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CopyPasteUtil.java
index 3f5103aa1d4..6adfd7ac346 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CopyPasteUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/CopyPasteUtil.java
@@ -1,185 +1,185 @@
-/*****************************************************************************
- * Copyright (c) 2017 CEA LIST 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:
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import org.eclipse.draw2d.FigureCanvas;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EcoreUtil;
-import org.eclipse.gef.EditPartViewer;
-import org.eclipse.gef.commands.Command;
-import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
-import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
-import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Different utility methods prior to paste command.
- * @since 3.0
- */
-public class CopyPasteUtil {
-
- // TODO: should be provided configurable in prefs
- public static final int DEFAULT_AVOID_SUPERPOSITION_Y = 10;
-
- // TODO: should be provided configurable in prefs
- public static final int DEFAULT_AVOID_SUPERPOSITION_X = 10;
-
-
- /**
- * Shift position to avoid overlap
- *
- * @param point
- * @return
- */
- public static Point shiftLayout(Point point) {
- return new Point(point.x + DEFAULT_AVOID_SUPERPOSITION_X, point.y + DEFAULT_AVOID_SUPERPOSITION_Y);
- }
-
- /**
- * @param targetEditPart
- * @return
- */
-
- public static Point getCursorPosition(GraphicalEditPart targetEditPart) {
- Display display = Display.getDefault();
- org.eclipse.swt.graphics.Point cursorLocation = display.getCursorLocation();
- EditPartViewer viewer = targetEditPart.getViewer();
- Control control = viewer.getControl();
- org.eclipse.swt.graphics.Point point = control.toControl(cursorLocation);
- FigureCanvas figureCanvas = (FigureCanvas) control;
- Point location = figureCanvas.getViewport().getViewLocation();
- return new Point(point.x + location.x, point.y + location.y);
- }
-
-
- /**
- * @param collection
- * @return
- */
-
- public static Collection<EObject> filterEObject(Collection<Object> collection) {
- List<EObject> eobjectList = new ArrayList<EObject>();
- for (Object object : collection) {
- if (object instanceof EObject) {
- eobjectList.add((EObject) object);
- }
- }
- return eobjectList;
- }
-
-
- /**
- * @param copier
- * @return
- */
-
- public static Map<Object, EObject> transtypeCopier(EcoreUtil.Copier copier) {
- Map<Object, EObject> map = new HashMap<Object, EObject>();
- Set<Entry<EObject, EObject>> entrySet = copier.entrySet();
- for (Entry<EObject, EObject> entry : entrySet) {
- map.put(entry.getKey(), entry.getValue());
- }
- return map;
- }
-
- /**
- * Look in the list of the children editParts, the one that accept the create view request
- *
- * @param targetEditPart
- * @param view
- * @return
- */
- public static GraphicalEditPart lookForTargetEditPart(GraphicalEditPart targetEditPart, View view){
- List<?> children = targetEditPart.getChildren();
- PreferencesHint prefs = ((IDiagramPreferenceSupport) targetEditPart.getRoot()).getPreferencesHint();
- CreateViewRequest request = new CreateViewRequest(view.getElement(), prefs);
- for (Object object : children) {
- if (object instanceof GraphicalEditPart) {
- GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
- Command command = graphicalEditPart.getCommand(request);
- if (command != null) {
- return graphicalEditPart;
- }
- }
- }
- return null;
- }
-
- /**
- * Look in sub container for a dropcommand
- *
- * @param targetEditPart
- * @param objectToDrop
- * @return
- */
- public static Command lookForCommandInSubContainer(GraphicalEditPart targetEditPart, List<EObject> objectToDrop) {
- List<?> children = targetEditPart.getChildren();
- DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
- for (Object object : children) {
- if (object instanceof GraphicalEditPart) {
- GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
- Point center = graphicalEditPart.getFigure().getBounds().getCenter();
- dropObjectsRequest.setLocation(center);
- dropObjectsRequest.setObjects(objectToDrop);
- Command command = graphicalEditPart.getCommand(dropObjectsRequest);
- if (command != null) {
- return command;
- }
- }
- }
- return null;
- }
-
- /**
- *
- * Look in sub container for a dropcommand
- *
- * @param targetEditPart
- * @param semanticObjects
- * @param newLocation
- * @return
- */
- public static Command lookForCommandInSubContainer(GraphicalEditPart targetEditPart, List<EObject> semanticObjects, Point newLocation) {
- List<?> children = targetEditPart.getChildren();
- DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
- for (Object object : children) {
- if (object instanceof GraphicalEditPart) {
- GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
- dropObjectsRequest.setLocation(newLocation);
- dropObjectsRequest.setObjects(semanticObjects);
- Command command = graphicalEditPart.getCommand(dropObjectsRequest);
- if (command != null) {
- return command;
- }
- }
-
- }
- return null;
- }
-
-
-}
+/*****************************************************************************
+ * Copyright (c) 2017 CEA LIST 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:
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import org.eclipse.draw2d.FigureCanvas;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.gef.EditPartViewer;
+import org.eclipse.gef.commands.Command;
+import org.eclipse.gmf.runtime.diagram.core.preferences.PreferencesHint;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.GraphicalEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.IDiagramPreferenceSupport;
+import org.eclipse.gmf.runtime.diagram.ui.requests.CreateViewRequest;
+import org.eclipse.gmf.runtime.diagram.ui.requests.DropObjectsRequest;
+import org.eclipse.gmf.runtime.notation.View;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Different utility methods prior to paste command.
+ * @since 3.0
+ */
+public class CopyPasteUtil {
+
+ // TODO: should be provided configurable in prefs
+ public static final int DEFAULT_AVOID_SUPERPOSITION_Y = 10;
+
+ // TODO: should be provided configurable in prefs
+ public static final int DEFAULT_AVOID_SUPERPOSITION_X = 10;
+
+
+ /**
+ * Shift position to avoid overlap
+ *
+ * @param point
+ * @return
+ */
+ public static Point shiftLayout(Point point) {
+ return new Point(point.x + DEFAULT_AVOID_SUPERPOSITION_X, point.y + DEFAULT_AVOID_SUPERPOSITION_Y);
+ }
+
+ /**
+ * @param targetEditPart
+ * @return
+ */
+
+ public static Point getCursorPosition(GraphicalEditPart targetEditPart) {
+ Display display = Display.getDefault();
+ org.eclipse.swt.graphics.Point cursorLocation = display.getCursorLocation();
+ EditPartViewer viewer = targetEditPart.getViewer();
+ Control control = viewer.getControl();
+ org.eclipse.swt.graphics.Point point = control.toControl(cursorLocation);
+ FigureCanvas figureCanvas = (FigureCanvas) control;
+ Point location = figureCanvas.getViewport().getViewLocation();
+ return new Point(point.x + location.x, point.y + location.y);
+ }
+
+
+ /**
+ * @param collection
+ * @return
+ */
+
+ public static Collection<EObject> filterEObject(Collection<Object> collection) {
+ List<EObject> eobjectList = new ArrayList<EObject>();
+ for (Object object : collection) {
+ if (object instanceof EObject) {
+ eobjectList.add((EObject) object);
+ }
+ }
+ return eobjectList;
+ }
+
+
+ /**
+ * @param copier
+ * @return
+ */
+
+ public static Map<Object, EObject> transtypeCopier(EcoreUtil.Copier copier) {
+ Map<Object, EObject> map = new HashMap<Object, EObject>();
+ Set<Entry<EObject, EObject>> entrySet = copier.entrySet();
+ for (Entry<EObject, EObject> entry : entrySet) {
+ map.put(entry.getKey(), entry.getValue());
+ }
+ return map;
+ }
+
+ /**
+ * Look in the list of the children editParts, the one that accept the create view request
+ *
+ * @param targetEditPart
+ * @param view
+ * @return
+ */
+ public static GraphicalEditPart lookForTargetEditPart(GraphicalEditPart targetEditPart, View view){
+ List<?> children = targetEditPart.getChildren();
+ PreferencesHint prefs = ((IDiagramPreferenceSupport) targetEditPart.getRoot()).getPreferencesHint();
+ CreateViewRequest request = new CreateViewRequest(view.getElement(), prefs);
+ for (Object object : children) {
+ if (object instanceof GraphicalEditPart) {
+ GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
+ Command command = graphicalEditPart.getCommand(request);
+ if (command != null) {
+ return graphicalEditPart;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Look in sub container for a dropcommand
+ *
+ * @param targetEditPart
+ * @param objectToDrop
+ * @return
+ */
+ public static Command lookForCommandInSubContainer(GraphicalEditPart targetEditPart, List<EObject> objectToDrop) {
+ List<?> children = targetEditPart.getChildren();
+ DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
+ for (Object object : children) {
+ if (object instanceof GraphicalEditPart) {
+ GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
+ Point center = graphicalEditPart.getFigure().getBounds().getCenter();
+ dropObjectsRequest.setLocation(center);
+ dropObjectsRequest.setObjects(objectToDrop);
+ Command command = graphicalEditPart.getCommand(dropObjectsRequest);
+ if (command != null) {
+ return command;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ *
+ * Look in sub container for a dropcommand
+ *
+ * @param targetEditPart
+ * @param semanticObjects
+ * @param newLocation
+ * @return
+ */
+ public static Command lookForCommandInSubContainer(GraphicalEditPart targetEditPart, List<EObject> semanticObjects, Point newLocation) {
+ List<?> children = targetEditPart.getChildren();
+ DropObjectsRequest dropObjectsRequest = new DropObjectsRequest();
+ for (Object object : children) {
+ if (object instanceof GraphicalEditPart) {
+ GraphicalEditPart graphicalEditPart = (GraphicalEditPart) object;
+ dropObjectsRequest.setLocation(newLocation);
+ dropObjectsRequest.setObjects(semanticObjects);
+ Command command = graphicalEditPart.getCommand(dropObjectsRequest);
+ if (command != null) {
+ return command;
+ }
+ }
+
+ }
+ return null;
+ }
+
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/EditPartUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/EditPartUtils.java
index dde77ced481..55b95fda058 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/EditPartUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/EditPartUtils.java
@@ -1,112 +1,112 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.TreeMap;
-
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gef.GraphicalEditPart;
-import org.eclipse.gmf.runtime.notation.View;
-
-/**
- * @since 3.0
- */
-public class EditPartUtils {
-
-
- public static EditPart findFirstChildEditPartWithId(final EditPart editPart, final String visualId) {
- final List<? extends EditPart> result = findChildEditPartsWithId(editPart, visualId);
- if (result.isEmpty()) {
- return null;
- }
- return result.get(0);
- }
-
- public static List<? extends EditPart> findChildEditPartsWithId(final EditPart editPart, final String visualId) {
- final List<EditPart> editParts = new ArrayList<EditPart>();
- internalFindChildEditPartsWithId(editPart, visualId, editParts);
- return editParts;
- }
-
- private static void internalFindChildEditPartsWithId(final EditPart editPart, final String visualId, final List<EditPart> result) {
- final Object model = editPart.getModel();
- if (model instanceof View) {
- final View view = (View) model;
- if( view.getType()!=null) {
- if (view.getType().equals(visualId)) {
- result.add(editPart);
- }
- }
- }
- @SuppressWarnings("unchecked")
- final List<EditPart> children = editPart.getChildren();
- for (final EditPart child : children) {
- internalFindChildEditPartsWithId(child, visualId, result);
- }
- }
-
- public static EditPart findParentEditPartWithId(final EditPart editPart, final String visualId) {
- EditPart parent = editPart;
- while (parent != null) {
- final Object model = parent.getModel();
- if (model instanceof View) {
- final View parentView = (View) model;
- if (parentView.getType()!=null) {
- if (parentView.getType().equals(visualId)) {
- return parent;
- }
- }
- parent = parent.getParent();
- } else {
- break;
- }
- }
- return null;
- }
-
- /**
- * Find the EditPart whose Figure is closest to the given y-coordinate.
- *
- * @param ordinate
- * the y-coordinate
- * @param editParts
- * the EditParts among which to choose
- * @return the EditPart closest to the given vertical coordinate
- */
- public static GraphicalEditPart findEditPartClosestToOrdinate(final int ordinate, final List<? extends GraphicalEditPart> editParts) {
- if (editParts.isEmpty()) {
- return null;
- }
-
- final TreeMap<Integer, GraphicalEditPart> distanceMap = new TreeMap<Integer, GraphicalEditPart>();
- for (final GraphicalEditPart editPart : editParts) {
- final IFigure figure = editPart.getFigure();
- final Rectangle bounds = new Rectangle(figure.getBounds());
- figure.getParent().translateToAbsolute(bounds);
- final int posY = bounds.y + bounds.height / 2;
- final int distance = Math.abs(posY - ordinate);
- distanceMap.put(Integer.valueOf(distance), editPart);
- }
- return distanceMap.values().iterator().next();
- }
-
-
- /** Reveals the given EditPart in its viewer */
- public static void revealEditPart(final EditPart editPart) {
- if (editPart != null && editPart.getViewer() != null) {
- editPart.getViewer().reveal(editPart);
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeMap;
+
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gef.GraphicalEditPart;
+import org.eclipse.gmf.runtime.notation.View;
+
+/**
+ * @since 3.0
+ */
+public class EditPartUtils {
+
+
+ public static EditPart findFirstChildEditPartWithId(final EditPart editPart, final String visualId) {
+ final List<? extends EditPart> result = findChildEditPartsWithId(editPart, visualId);
+ if (result.isEmpty()) {
+ return null;
+ }
+ return result.get(0);
+ }
+
+ public static List<? extends EditPart> findChildEditPartsWithId(final EditPart editPart, final String visualId) {
+ final List<EditPart> editParts = new ArrayList<EditPart>();
+ internalFindChildEditPartsWithId(editPart, visualId, editParts);
+ return editParts;
+ }
+
+ private static void internalFindChildEditPartsWithId(final EditPart editPart, final String visualId, final List<EditPart> result) {
+ final Object model = editPart.getModel();
+ if (model instanceof View) {
+ final View view = (View) model;
+ if( view.getType()!=null) {
+ if (view.getType().equals(visualId)) {
+ result.add(editPart);
+ }
+ }
+ }
+ @SuppressWarnings("unchecked")
+ final List<EditPart> children = editPart.getChildren();
+ for (final EditPart child : children) {
+ internalFindChildEditPartsWithId(child, visualId, result);
+ }
+ }
+
+ public static EditPart findParentEditPartWithId(final EditPart editPart, final String visualId) {
+ EditPart parent = editPart;
+ while (parent != null) {
+ final Object model = parent.getModel();
+ if (model instanceof View) {
+ final View parentView = (View) model;
+ if (parentView.getType()!=null) {
+ if (parentView.getType().equals(visualId)) {
+ return parent;
+ }
+ }
+ parent = parent.getParent();
+ } else {
+ break;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Find the EditPart whose Figure is closest to the given y-coordinate.
+ *
+ * @param ordinate
+ * the y-coordinate
+ * @param editParts
+ * the EditParts among which to choose
+ * @return the EditPart closest to the given vertical coordinate
+ */
+ public static GraphicalEditPart findEditPartClosestToOrdinate(final int ordinate, final List<? extends GraphicalEditPart> editParts) {
+ if (editParts.isEmpty()) {
+ return null;
+ }
+
+ final TreeMap<Integer, GraphicalEditPart> distanceMap = new TreeMap<Integer, GraphicalEditPart>();
+ for (final GraphicalEditPart editPart : editParts) {
+ final IFigure figure = editPart.getFigure();
+ final Rectangle bounds = new Rectangle(figure.getBounds());
+ figure.getParent().translateToAbsolute(bounds);
+ final int posY = bounds.y + bounds.height / 2;
+ final int distance = Math.abs(posY - ordinate);
+ distanceMap.put(Integer.valueOf(distance), editPart);
+ }
+ return distanceMap.values().iterator().next();
+ }
+
+
+ /** Reveals the given EditPart in its viewer */
+ public static void revealEditPart(final EditPart editPart) {
+ if (editPart != null && editPart.getViewer() != null) {
+ editPart.getViewer().reveal(editPart);
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java
index 04635b079f7..9954f359077 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/FigureUtils.java
@@ -1,151 +1,151 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- *
- * 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
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.draw2d.FigureUtilities;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.LayeredPane;
-import org.eclipse.draw2d.ScalableFigure;
-import org.eclipse.draw2d.geometry.Point;
-import org.eclipse.draw2d.geometry.Rectangle;
-import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
-
-public final class FigureUtils {
-
- private FigureUtils() {
- // utility class
- }
-
- /**
- * Returns a child figure of the given type recursively contained in the given parent figure.
- *
- * @param parent
- * the parent figure
- * @param childFigureClass
- * the type of the child figure that is looked for
- * @return the child figure if found, or <code>null</code> if the parent figure contains no child figure of the
- * given type
- */
- @SuppressWarnings("unchecked")
- public static <T extends IFigure> T findChildFigureInstance(final IFigure parent, final Class<T> childFigureClass) {
- final List<IFigure> children = parent.getChildren();
- for (final IFigure child : children) {
- if (childFigureClass.isAssignableFrom(child.getClass())) {
- return (T) child;
- }
- // look recursively
- final IFigure subresult = findChildFigureInstance(child, childFigureClass);
- if (subresult != null) {
- return (T) subresult;
- }
- }
- // not found
- return null;
- }
-
- public static <T extends IFigure> List<T> findChildFigureInstances(final IFigure parent, final Class<T> childFigureClass) {
- final List<T> result = new ArrayList<>();
- internalFindChildFigureInstances(parent, result, childFigureClass);
- return result;
- }
-
- @SuppressWarnings("unchecked")
- public static <T extends IFigure> void internalFindChildFigureInstances(final IFigure parent, final List<T> result, final Class<T> childFigureClass) {
- if (parent == null) {
- return;
- }
- final List<IFigure> children = parent.getChildren();
- for (final IFigure child : children) {
- if (childFigureClass.isAssignableFrom(child.getClass())) {
- result.add((T) child);
- } else {
- internalFindChildFigureInstances(child, result, childFigureClass);
- }
-
- }
- }
-
- /**
- * Returns the first parent figure of the given type recursively containing the given figure.
- *
- * @param figure
- * the figure
- * @param parentFigureClass
- * the type of the parent figure that is looked for
- * @return the parent figure if found, or <code>null</code> if the figure is not contained by any figure of the
- * given type
- */
- @SuppressWarnings("unchecked")
- public static <T extends IFigure> T findParentFigureInstance(final IFigure figure, final Class<T> parentFigureClass) {
- IFigure parent = figure.getParent();
- while (parent != null) {
- if (parentFigureClass.isAssignableFrom(parent.getClass())) {
- return (T) parent;
- }
- parent = parent.getParent();
- }
- return null;
- }
-
- /**
- * Constrain the given bounds (whose presumed purpose is to become the new bounds for the given Figure), so that
- * they don't stick out of the bounds of the {@link ResizableCompartmentFigure} in which the given figure is
- * contained. Returns the original bounds if the given Figure is not contained in a {@link ResizableCompartmentFigure}.
- *
- * @param bounds
- * The bounds to constrain (will not be modified)
- * @param figure
- * the figure in the containing {@link ResizableCompartmentFigure} of which the bound must be constrained
- * @return the bounds, constrained so that they don't stick out of the {@link ResizableCompartmentFigure} in which
- * the Figure is contained
- *
- */
- public static Rectangle constrainBoundsWithinContainingCompartment(final Rectangle bounds, final IFigure figure) {
- final Rectangle result = new Rectangle(bounds);
- final ResizableCompartmentFigure parentCompartment = FigureUtils.findParentFigureInstance(figure, ResizableCompartmentFigure.class);
- if (parentCompartment == null) {
- return result;
- }
- final Rectangle parentBounds = parentCompartment.getBounds();
- result.x = Math.max(result.x, 0);
- result.y = Math.max(result.y, 0);
- result.x = Math.min(result.x, parentBounds.width - result.width);
- result.y = Math.min(result.y, parentBounds.height - result.height);
- return result;
- }
-
- /**
- * @return The origin of the coordinate system applied to the given figure (i.e.: the amount scrolled in the scroll
- * pane)
- */
- public static Point getLayeredPaneOrigin(final IFigure figure) {
- final LayeredPane layeredPane = FigureUtils.findChildFigureInstance(FigureUtilities.getRoot(figure), LayeredPane.class);
- final Point origin = new Point(0, 0);
- layeredPane.translateToRelative(origin);
- return origin;
- }
-
- /**
- * @return The scale applied to the given figure (i.e.: the zoom set by the user)
- */
- public static double getScale(final IFigure figure) {
- final ScalableFigure scalableFigure = FigureUtils.findParentFigureInstance(figure, ScalableFigure.class);
- return scalableFigure.getScale();
- }
-
- public static Point scaleByZoom(final Point delta, final IFigure figure) {
- return new Point(delta).scale(1.0 / getScale(figure));
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ *
+ * 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
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.draw2d.FigureUtilities;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LayeredPane;
+import org.eclipse.draw2d.ScalableFigure;
+import org.eclipse.draw2d.geometry.Point;
+import org.eclipse.draw2d.geometry.Rectangle;
+import org.eclipse.gmf.runtime.diagram.ui.figures.ResizableCompartmentFigure;
+
+public final class FigureUtils {
+
+ private FigureUtils() {
+ // utility class
+ }
+
+ /**
+ * Returns a child figure of the given type recursively contained in the given parent figure.
+ *
+ * @param parent
+ * the parent figure
+ * @param childFigureClass
+ * the type of the child figure that is looked for
+ * @return the child figure if found, or <code>null</code> if the parent figure contains no child figure of the
+ * given type
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends IFigure> T findChildFigureInstance(final IFigure parent, final Class<T> childFigureClass) {
+ final List<IFigure> children = parent.getChildren();
+ for (final IFigure child : children) {
+ if (childFigureClass.isAssignableFrom(child.getClass())) {
+ return (T) child;
+ }
+ // look recursively
+ final IFigure subresult = findChildFigureInstance(child, childFigureClass);
+ if (subresult != null) {
+ return (T) subresult;
+ }
+ }
+ // not found
+ return null;
+ }
+
+ public static <T extends IFigure> List<T> findChildFigureInstances(final IFigure parent, final Class<T> childFigureClass) {
+ final List<T> result = new ArrayList<>();
+ internalFindChildFigureInstances(parent, result, childFigureClass);
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends IFigure> void internalFindChildFigureInstances(final IFigure parent, final List<T> result, final Class<T> childFigureClass) {
+ if (parent == null) {
+ return;
+ }
+ final List<IFigure> children = parent.getChildren();
+ for (final IFigure child : children) {
+ if (childFigureClass.isAssignableFrom(child.getClass())) {
+ result.add((T) child);
+ } else {
+ internalFindChildFigureInstances(child, result, childFigureClass);
+ }
+
+ }
+ }
+
+ /**
+ * Returns the first parent figure of the given type recursively containing the given figure.
+ *
+ * @param figure
+ * the figure
+ * @param parentFigureClass
+ * the type of the parent figure that is looked for
+ * @return the parent figure if found, or <code>null</code> if the figure is not contained by any figure of the
+ * given type
+ */
+ @SuppressWarnings("unchecked")
+ public static <T extends IFigure> T findParentFigureInstance(final IFigure figure, final Class<T> parentFigureClass) {
+ IFigure parent = figure.getParent();
+ while (parent != null) {
+ if (parentFigureClass.isAssignableFrom(parent.getClass())) {
+ return (T) parent;
+ }
+ parent = parent.getParent();
+ }
+ return null;
+ }
+
+ /**
+ * Constrain the given bounds (whose presumed purpose is to become the new bounds for the given Figure), so that
+ * they don't stick out of the bounds of the {@link ResizableCompartmentFigure} in which the given figure is
+ * contained. Returns the original bounds if the given Figure is not contained in a {@link ResizableCompartmentFigure}.
+ *
+ * @param bounds
+ * The bounds to constrain (will not be modified)
+ * @param figure
+ * the figure in the containing {@link ResizableCompartmentFigure} of which the bound must be constrained
+ * @return the bounds, constrained so that they don't stick out of the {@link ResizableCompartmentFigure} in which
+ * the Figure is contained
+ *
+ */
+ public static Rectangle constrainBoundsWithinContainingCompartment(final Rectangle bounds, final IFigure figure) {
+ final Rectangle result = new Rectangle(bounds);
+ final ResizableCompartmentFigure parentCompartment = FigureUtils.findParentFigureInstance(figure, ResizableCompartmentFigure.class);
+ if (parentCompartment == null) {
+ return result;
+ }
+ final Rectangle parentBounds = parentCompartment.getBounds();
+ result.x = Math.max(result.x, 0);
+ result.y = Math.max(result.y, 0);
+ result.x = Math.min(result.x, parentBounds.width - result.width);
+ result.y = Math.min(result.y, parentBounds.height - result.height);
+ return result;
+ }
+
+ /**
+ * @return The origin of the coordinate system applied to the given figure (i.e.: the amount scrolled in the scroll
+ * pane)
+ */
+ public static Point getLayeredPaneOrigin(final IFigure figure) {
+ final LayeredPane layeredPane = FigureUtils.findChildFigureInstance(FigureUtilities.getRoot(figure), LayeredPane.class);
+ final Point origin = new Point(0, 0);
+ layeredPane.translateToRelative(origin);
+ return origin;
+ }
+
+ /**
+ * @return The scale applied to the given figure (i.e.: the zoom set by the user)
+ */
+ public static double getScale(final IFigure figure) {
+ final ScalableFigure scalableFigure = FigureUtils.findParentFigureInstance(figure, ScalableFigure.class);
+ return scalableFigure.getScale();
+ }
+
+ public static Point scaleByZoom(final Point delta, final IFigure figure) {
+ return new Point(delta).scale(1.0 / getScale(figure));
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/HighlightUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/HighlightUtil.java
index ab414f2b5f0..4cdb1200a68 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/HighlightUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/HighlightUtil.java
@@ -1,236 +1,236 @@
-/*****************************************************************************
- * Copyright (c) 2015 CEA LIST.
- *
- * 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:
- * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.eclipse.draw2d.Border;
-import org.eclipse.draw2d.IFigure;
-import org.eclipse.draw2d.LineBorder;
-import org.eclipse.draw2d.Shape;
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
-import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
-import org.eclipse.gmf.runtime.notation.FillStyle;
-import org.eclipse.gmf.runtime.notation.LineStyle;
-
-import org.eclipse.swt.graphics.Color;
-
-/**
- * Util methods dedicated to help for the highlight of node/edge in case of mouseover.
- * @author flefevre
- *
- */
-public class HighlightUtil {
-
- private static class FigureState {
-
- private Color bgColor;
-
- private Color fgColor;
-
- private int lineWidth;
-
- public FigureState(Color bgColor, Color fgColor, int lineWidth) {
- this.bgColor = bgColor;
- this.fgColor = fgColor;
- this.lineWidth = lineWidth;
- }
- }
-
- private static Map<Object, FigureState> figureState = new HashMap<Object, FigureState>();
-
- /**
- * Make a private instance, avoid highlight above highlight.
- */
- private HighlightUtil() {
- }
-
- /**
- * Maybe this value can be managed by preferences.
- *
- * @param bgColor
- */
- private static Color getHighlightBackground(Color bgColor) {
- return bgColor;
- }
-
- /**
- * Maybe this value can be managed by preferences.
- *
- * @param lineWidth
- */
- private static int getHighlightLineWidth(int lineWidth) {
- return lineWidth * 2;
- }
-
- private static List<IFigure> getHighlightFigures(EditPart host, boolean parentLooking) {
- List<IFigure> figures = new ArrayList<IFigure>();
- try {
- Method getMethod = getGetPrimaryShapeMethod(host.getClass());
- getMethod.setAccessible(true);
- figures.add((IFigure) getMethod.invoke(host));
- } catch (Exception e) {
- if(!parentLooking){
- List<IFigure> po = getHighlightFigures(host.getParent(), true);
- if(po!=null){
- figures.addAll(po);
- }
- }
-
- }
- return figures;
- }
-
- /**
- * Fixed bug when introducing some sub class.
- *
- * @param type
- * @return getPrimaryShape()
- * @throws Exception
- */
- protected static Method getGetPrimaryShapeMethod(Class<?> type) throws Exception {
- if (type == null) {
- throw new NoSuchMethodException("getPrimaryShape");
- }
- try {
- return type.getDeclaredMethod("getPrimaryShape");
- } catch (Exception e) {
- Method method = getGetPrimaryShapeMethod(type.getSuperclass());
- if (method == null) {
- throw e;
- }
- return method;
- }
- }
-
- /**
- * Maybe this value can be managed by preferences.
- *
- * @param fgColor
- */
- private static Color getHighlightForeground(Color fgColor) {
- return fgColor;
- }
-
- public static void highlight(EditPart host) {
- List<IFigure> highlightFigures = getHighlightFigures(host, false);
- if (highlightFigures.isEmpty()) {
- return;
- }
- synchronized (figureState) {
- for (IFigure figure : highlightFigures) {
- FigureState fs = figureState.get(figure);
- if (fs == null) {
- fs = createFigureState(host, figure);
- figureState.put(figure, fs);
- }
- updateFigure(figure, getHighlightBackground(fs.bgColor), getHighlightForeground(fs.fgColor), getHighlightLineWidth(fs.lineWidth));
- }
- }
- }
-
- protected static FigureState createFigureState(EditPart host, IFigure fig) {
- int lineWidth = 1;
- Color bgColor = null, fgColor = null;
- Object model = host.getModel();
- if (model instanceof LineStyle) {
- int modelLineWidth = ((LineStyle) model).getLineWidth();
- if (modelLineWidth != -1) {
- lineWidth = modelLineWidth;
- }
- int lineColor = ((LineStyle) model).getLineColor();
- fgColor = DiagramColorRegistry.getInstance().getColor(Integer.valueOf(lineColor));
- } else {
- Border border = fig.getBorder();
- if (border instanceof LineBorder) {
- lineWidth = ((LineBorder) border).getWidth();
- } else if (fig instanceof Shape) {
- lineWidth = ((Shape) fig).getLineWidth();
- }
- fgColor = fig.getForegroundColor();
- }
- if (model instanceof FillStyle) {
- int fillColor = ((FillStyle) model).getFillColor();
- bgColor = DiagramColorRegistry.getInstance().getColor(Integer.valueOf(fillColor));
- } else {
- bgColor = fig.getBackgroundColor();
- }
- return new FigureState(bgColor, fgColor, lineWidth);
- }
-
- public static void unhighlight() {
- if (figureState == null || figureState.isEmpty()) {
- return;
- }
- synchronized (figureState) {
- Set<Entry<Object, FigureState>> entrySet = figureState.entrySet();
- for (Entry<Object, FigureState> entry : entrySet) {
- Object key = entry.getKey();
- FigureState value = entry.getValue();
- if (key instanceof IFigure) {
- IFigure fig = (IFigure) key;
- updateFigure(fig, value.bgColor, value.fgColor, value.lineWidth);
- } else if (key instanceof EditPart) {
- List<IFigure> figures = getHighlightFigures((EditPart) key, false);
- for (IFigure fig : figures) {
- updateFigure(fig, value.bgColor, value.fgColor, value.lineWidth);
- }
- }
- }
- figureState.clear();
- }
- }
-
- public static void unhighlight(EditPart host) {
- List<IFigure> highlightFigures = getHighlightFigures(host, false);
- if (highlightFigures.isEmpty()) {
- return;
- }
- synchronized (figureState) {
- for (IFigure figure : highlightFigures) {
- FigureState s = figureState.remove(figure);
- if (s == null) {
- continue;
- }
- updateFigure(figure, s.bgColor, s.fgColor, s.lineWidth);
- }
- }
- }
-
- private static void updateFigure(IFigure fig, Color bgColor, Color fgColor, int lineWidth) {
- if (fig == null) {
- return;
- }
- synchronized (fig) {
- if (lineWidth > 0) {
- Border border = fig.getBorder();
- if (border != null && border instanceof LineBorder) {
- ((LineBorder) border).setWidth(lineWidth);
- }
- if (fig instanceof Shape) {
- ((Shape) fig).setLineWidth(lineWidth);
- }
- if (fig instanceof NodeFigure) {
- ((NodeFigure) fig).setLineWidth(lineWidth);
- }
- }
- fig.repaint();
- }
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2015 CEA LIST.
+ *
+ * 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:
+ * Francois Le Fevre (CEA LIST) francois.le-fevre@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import org.eclipse.draw2d.Border;
+import org.eclipse.draw2d.IFigure;
+import org.eclipse.draw2d.LineBorder;
+import org.eclipse.draw2d.Shape;
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.l10n.DiagramColorRegistry;
+import org.eclipse.gmf.runtime.gef.ui.figures.NodeFigure;
+import org.eclipse.gmf.runtime.notation.FillStyle;
+import org.eclipse.gmf.runtime.notation.LineStyle;
+
+import org.eclipse.swt.graphics.Color;
+
+/**
+ * Util methods dedicated to help for the highlight of node/edge in case of mouseover.
+ * @author flefevre
+ *
+ */
+public class HighlightUtil {
+
+ private static class FigureState {
+
+ private Color bgColor;
+
+ private Color fgColor;
+
+ private int lineWidth;
+
+ public FigureState(Color bgColor, Color fgColor, int lineWidth) {
+ this.bgColor = bgColor;
+ this.fgColor = fgColor;
+ this.lineWidth = lineWidth;
+ }
+ }
+
+ private static Map<Object, FigureState> figureState = new HashMap<Object, FigureState>();
+
+ /**
+ * Make a private instance, avoid highlight above highlight.
+ */
+ private HighlightUtil() {
+ }
+
+ /**
+ * Maybe this value can be managed by preferences.
+ *
+ * @param bgColor
+ */
+ private static Color getHighlightBackground(Color bgColor) {
+ return bgColor;
+ }
+
+ /**
+ * Maybe this value can be managed by preferences.
+ *
+ * @param lineWidth
+ */
+ private static int getHighlightLineWidth(int lineWidth) {
+ return lineWidth * 2;
+ }
+
+ private static List<IFigure> getHighlightFigures(EditPart host, boolean parentLooking) {
+ List<IFigure> figures = new ArrayList<IFigure>();
+ try {
+ Method getMethod = getGetPrimaryShapeMethod(host.getClass());
+ getMethod.setAccessible(true);
+ figures.add((IFigure) getMethod.invoke(host));
+ } catch (Exception e) {
+ if(!parentLooking){
+ List<IFigure> po = getHighlightFigures(host.getParent(), true);
+ if(po!=null){
+ figures.addAll(po);
+ }
+ }
+
+ }
+ return figures;
+ }
+
+ /**
+ * Fixed bug when introducing some sub class.
+ *
+ * @param type
+ * @return getPrimaryShape()
+ * @throws Exception
+ */
+ protected static Method getGetPrimaryShapeMethod(Class<?> type) throws Exception {
+ if (type == null) {
+ throw new NoSuchMethodException("getPrimaryShape");
+ }
+ try {
+ return type.getDeclaredMethod("getPrimaryShape");
+ } catch (Exception e) {
+ Method method = getGetPrimaryShapeMethod(type.getSuperclass());
+ if (method == null) {
+ throw e;
+ }
+ return method;
+ }
+ }
+
+ /**
+ * Maybe this value can be managed by preferences.
+ *
+ * @param fgColor
+ */
+ private static Color getHighlightForeground(Color fgColor) {
+ return fgColor;
+ }
+
+ public static void highlight(EditPart host) {
+ List<IFigure> highlightFigures = getHighlightFigures(host, false);
+ if (highlightFigures.isEmpty()) {
+ return;
+ }
+ synchronized (figureState) {
+ for (IFigure figure : highlightFigures) {
+ FigureState fs = figureState.get(figure);
+ if (fs == null) {
+ fs = createFigureState(host, figure);
+ figureState.put(figure, fs);
+ }
+ updateFigure(figure, getHighlightBackground(fs.bgColor), getHighlightForeground(fs.fgColor), getHighlightLineWidth(fs.lineWidth));
+ }
+ }
+ }
+
+ protected static FigureState createFigureState(EditPart host, IFigure fig) {
+ int lineWidth = 1;
+ Color bgColor = null, fgColor = null;
+ Object model = host.getModel();
+ if (model instanceof LineStyle) {
+ int modelLineWidth = ((LineStyle) model).getLineWidth();
+ if (modelLineWidth != -1) {
+ lineWidth = modelLineWidth;
+ }
+ int lineColor = ((LineStyle) model).getLineColor();
+ fgColor = DiagramColorRegistry.getInstance().getColor(Integer.valueOf(lineColor));
+ } else {
+ Border border = fig.getBorder();
+ if (border instanceof LineBorder) {
+ lineWidth = ((LineBorder) border).getWidth();
+ } else if (fig instanceof Shape) {
+ lineWidth = ((Shape) fig).getLineWidth();
+ }
+ fgColor = fig.getForegroundColor();
+ }
+ if (model instanceof FillStyle) {
+ int fillColor = ((FillStyle) model).getFillColor();
+ bgColor = DiagramColorRegistry.getInstance().getColor(Integer.valueOf(fillColor));
+ } else {
+ bgColor = fig.getBackgroundColor();
+ }
+ return new FigureState(bgColor, fgColor, lineWidth);
+ }
+
+ public static void unhighlight() {
+ if (figureState == null || figureState.isEmpty()) {
+ return;
+ }
+ synchronized (figureState) {
+ Set<Entry<Object, FigureState>> entrySet = figureState.entrySet();
+ for (Entry<Object, FigureState> entry : entrySet) {
+ Object key = entry.getKey();
+ FigureState value = entry.getValue();
+ if (key instanceof IFigure) {
+ IFigure fig = (IFigure) key;
+ updateFigure(fig, value.bgColor, value.fgColor, value.lineWidth);
+ } else if (key instanceof EditPart) {
+ List<IFigure> figures = getHighlightFigures((EditPart) key, false);
+ for (IFigure fig : figures) {
+ updateFigure(fig, value.bgColor, value.fgColor, value.lineWidth);
+ }
+ }
+ }
+ figureState.clear();
+ }
+ }
+
+ public static void unhighlight(EditPart host) {
+ List<IFigure> highlightFigures = getHighlightFigures(host, false);
+ if (highlightFigures.isEmpty()) {
+ return;
+ }
+ synchronized (figureState) {
+ for (IFigure figure : highlightFigures) {
+ FigureState s = figureState.remove(figure);
+ if (s == null) {
+ continue;
+ }
+ updateFigure(figure, s.bgColor, s.fgColor, s.lineWidth);
+ }
+ }
+ }
+
+ private static void updateFigure(IFigure fig, Color bgColor, Color fgColor, int lineWidth) {
+ if (fig == null) {
+ return;
+ }
+ synchronized (fig) {
+ if (lineWidth > 0) {
+ Border border = fig.getBorder();
+ if (border != null && border instanceof LineBorder) {
+ ((LineBorder) border).setWidth(lineWidth);
+ }
+ if (fig instanceof Shape) {
+ ((Shape) fig).setLineWidth(lineWidth);
+ }
+ if (fig instanceof NodeFigure) {
+ ((NodeFigure) fig).setLineWidth(lineWidth);
+ }
+ }
+ fig.repaint();
+ }
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/LineStyleEnum.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/LineStyleEnum.java
index e53e4ef49e4..1053540844f 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/LineStyleEnum.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/LineStyleEnum.java
@@ -1,112 +1,112 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST 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:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
- *
- *****************************************************************************/
-
-
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import org.eclipse.draw2d.Graphics;
-
-
-/**
- * Enumeration to define line style as String related to the Open Declaration org.eclipse.draw2d.Graphics line styles
- *
- * @author Mickael ADAM
- *
- */
-public enum LineStyleEnum {
-
- /** The dash. */
- DASH(Graphics.LINE_DASH, "dash"), //$NON-NLS-1$
-
- /** The dash dot. */
- DASH_DOT(Graphics.LINE_DASHDOT, "dashDot"), //$NON-NLS-1$
-
- /** The dash dot dot. */
- DASH_DOT_DOT(Graphics.LINE_DASHDOTDOT, "dashDotDot"), //$NON-NLS-1$
-
- /** The dot. */
- DOT(Graphics.LINE_DOT, "dot"), //$NON-NLS-1$
-
- /** The solid. */
- SOLID(Graphics.LINE_SOLID, "solid"), //$NON-NLS-1$
-
- /** The custom. */
- CUSTOM(Graphics.LINE_CUSTOM, "custom"); //$NON-NLS-1$
-
- /** The line style. */
- private int lineStyle;
-
- /** The literal. */
- private String literal;
-
- /**
- * Instantiates a new line style enum.
- *
- * @param lineStyle
- * the line style
- * @param literal
- * the literal
- */
- private LineStyleEnum(int lineStyle, String literal) {
- this.lineStyle = lineStyle;
- this.literal = literal;
- }
-
- /**
- * Gets the line style.
- *
- * @return the line style
- */
- public int getLineStyle() {
- return lineStyle;
- }
-
- /**
- * Gets the literal.
- *
- * @return the literal
- */
- public String getLiteral() {
- return literal;
- }
-
- /** The Constant LINE_STYLE_ARRAY. */
- private static final LineStyleEnum[] LINE_STYLE_ARRAY = new LineStyleEnum[] { DASH, DASH_DOT, DASH_DOT_DOT, DOT, SOLID, CUSTOM, };
-
- /**
- * Gets the by literal.
- *
- * @param literal
- * the literal
- * @return the by literal
- */
- public static LineStyleEnum getByLiteral(String literal) {
- for (int i = 0; i < LINE_STYLE_ARRAY.length; ++i) {
- LineStyleEnum result = LINE_STYLE_ARRAY[i];
- if (result.getLiteral().equals(literal)) {
- return result;
- }
- }
- return null;
- }
-
- /**
- * Returns the literal value of the enumerator, which is its string representation.
- *
- * @return the string
- */
- @Override
- public String toString() {
- return literal;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+
+
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import org.eclipse.draw2d.Graphics;
+
+
+/**
+ * Enumeration to define line style as String related to the Open Declaration org.eclipse.draw2d.Graphics line styles
+ *
+ * @author Mickael ADAM
+ *
+ */
+public enum LineStyleEnum {
+
+ /** The dash. */
+ DASH(Graphics.LINE_DASH, "dash"), //$NON-NLS-1$
+
+ /** The dash dot. */
+ DASH_DOT(Graphics.LINE_DASHDOT, "dashDot"), //$NON-NLS-1$
+
+ /** The dash dot dot. */
+ DASH_DOT_DOT(Graphics.LINE_DASHDOTDOT, "dashDotDot"), //$NON-NLS-1$
+
+ /** The dot. */
+ DOT(Graphics.LINE_DOT, "dot"), //$NON-NLS-1$
+
+ /** The solid. */
+ SOLID(Graphics.LINE_SOLID, "solid"), //$NON-NLS-1$
+
+ /** The custom. */
+ CUSTOM(Graphics.LINE_CUSTOM, "custom"); //$NON-NLS-1$
+
+ /** The line style. */
+ private int lineStyle;
+
+ /** The literal. */
+ private String literal;
+
+ /**
+ * Instantiates a new line style enum.
+ *
+ * @param lineStyle
+ * the line style
+ * @param literal
+ * the literal
+ */
+ private LineStyleEnum(int lineStyle, String literal) {
+ this.lineStyle = lineStyle;
+ this.literal = literal;
+ }
+
+ /**
+ * Gets the line style.
+ *
+ * @return the line style
+ */
+ public int getLineStyle() {
+ return lineStyle;
+ }
+
+ /**
+ * Gets the literal.
+ *
+ * @return the literal
+ */
+ public String getLiteral() {
+ return literal;
+ }
+
+ /** The Constant LINE_STYLE_ARRAY. */
+ private static final LineStyleEnum[] LINE_STYLE_ARRAY = new LineStyleEnum[] { DASH, DASH_DOT, DASH_DOT_DOT, DOT, SOLID, CUSTOM, };
+
+ /**
+ * Gets the by literal.
+ *
+ * @param literal
+ * the literal
+ * @return the by literal
+ */
+ public static LineStyleEnum getByLiteral(String literal) {
+ for (int i = 0; i < LINE_STYLE_ARRAY.length; ++i) {
+ LineStyleEnum result = LINE_STYLE_ARRAY[i];
+ if (result.getLiteral().equals(literal)) {
+ return result;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Returns the literal value of the enumerator, which is its string representation.
+ *
+ * @return the string
+ */
+ @Override
+ public String toString() {
+ return literal;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PortPositionEnum.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PortPositionEnum.java
index df66158b6c4..75318f30b65 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PortPositionEnum.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PortPositionEnum.java
@@ -1,64 +1,64 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST 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:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
- *
- *****************************************************************************/
-
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-
-/**
- * The Enum PortPositionEnum for the position of ports on border.
- *
- * @author Mickael ADAM
- */
-public enum PortPositionEnum {
-
- /** The inside. */
- INSIDE("inside"), //$NON-NLS-1$
-
- /** The outside. */
- OUTSIDE("outside"), //$NON-NLS-1$
-
- /** The online. */
- ONLINE("onLine"); //$NON-NLS-1$
-
- /** The literal. */
- private String literal;
-
- /**
- * Instantiates a new port position enum.
- *
- * @param literal
- * the literal
- */
- private PortPositionEnum(String literal) {
- this.literal = literal;
- }
-
- /**
- * Gets the literal.
- *
- * @return the literal
- */
- public String getLiteral() {
- return literal;
- }
-
- /**
- * Returns the literal value of the enumerator, which is its string representation.
- *
- * @return the string
- */
- @Override
- public String toString() {
- return literal;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+
+/**
+ * The Enum PortPositionEnum for the position of ports on border.
+ *
+ * @author Mickael ADAM
+ */
+public enum PortPositionEnum {
+
+ /** The inside. */
+ INSIDE("inside"), //$NON-NLS-1$
+
+ /** The outside. */
+ OUTSIDE("outside"), //$NON-NLS-1$
+
+ /** The online. */
+ ONLINE("onLine"); //$NON-NLS-1$
+
+ /** The literal. */
+ private String literal;
+
+ /**
+ * Instantiates a new port position enum.
+ *
+ * @param literal
+ * the literal
+ */
+ private PortPositionEnum(String literal) {
+ this.literal = literal;
+ }
+
+ /**
+ * Gets the literal.
+ *
+ * @return the literal
+ */
+ public String getLiteral() {
+ return literal;
+ }
+
+ /**
+ * Returns the literal value of the enumerator, which is its string representation.
+ *
+ * @return the string
+ */
+ @Override
+ public String toString() {
+ return literal;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PositionEnum.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PositionEnum.java
index adbb905fb54..3eb152518ee 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PositionEnum.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/PositionEnum.java
@@ -1,98 +1,98 @@
-/*****************************************************************************
- * Copyright (c) 2010, 2014 CEA LIST 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:
- * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
- *
- *****************************************************************************/
-
-
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-
-/**
- * The Enum PositionEnum.
- *
- * @author Mickael ADAM
- */
-public enum PositionEnum {
-
- /** The north. */
- NORTH("NORTH", "north"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The south. */
- SOUTH("SOUTH", "south"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The east. */
- EAST("EAST", "east"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The west. */
- WEST("WEST", "west"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The none. */
- NONE("NONE", "none"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The auto. */
- AUTO("AUTO", "AUTO"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The left. */
- LEFT("LEFT", "left"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The right. */
- RIGHT("RIGHT", "right"), //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The center. */
- CENTER("CENTER", "center"); //$NON-NLS-1$ //$NON-NLS-2$
-
- /** The name. */
- private String name;
-
- /** The literal. */
- private String literal;
-
- /**
- * Instantiates a new position enum.
- *
- * @param name
- * the name
- * @param literal
- * the literal
- */
- private PositionEnum(String name, String literal) {
- this.name = name;
- this.literal = literal;
- }
-
- /**
- * Gets the name.
- *
- * @return the name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Gets the literal.
- *
- * @return the literal
- */
- public String getLiteral() {
- return literal;
- }
-
- /**
- * Returns the literal value of the enumerator, which is its string representation.
- *
- * @return the string
- */
- @Override
- public String toString() {
- return literal;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2010, 2014 CEA LIST 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:
+ * Mickael ADAM (ALL4TEC) mickael.adam@all4tec.net - Initial API and Implementation
+ *
+ *****************************************************************************/
+
+
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+
+/**
+ * The Enum PositionEnum.
+ *
+ * @author Mickael ADAM
+ */
+public enum PositionEnum {
+
+ /** The north. */
+ NORTH("NORTH", "north"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The south. */
+ SOUTH("SOUTH", "south"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The east. */
+ EAST("EAST", "east"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The west. */
+ WEST("WEST", "west"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The none. */
+ NONE("NONE", "none"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The auto. */
+ AUTO("AUTO", "AUTO"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The left. */
+ LEFT("LEFT", "left"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The right. */
+ RIGHT("RIGHT", "right"), //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The center. */
+ CENTER("CENTER", "center"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ /** The name. */
+ private String name;
+
+ /** The literal. */
+ private String literal;
+
+ /**
+ * Instantiates a new position enum.
+ *
+ * @param name
+ * the name
+ * @param literal
+ * the literal
+ */
+ private PositionEnum(String name, String literal) {
+ this.name = name;
+ this.literal = literal;
+ }
+
+ /**
+ * Gets the name.
+ *
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Gets the literal.
+ *
+ * @return the literal
+ */
+ public String getLiteral() {
+ return literal;
+ }
+
+ /**
+ * Returns the literal value of the enumerator, which is its string representation.
+ *
+ * @return the string
+ */
+ @Override
+ public String toString() {
+ return literal;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ServiceUtilsForEditPart.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ServiceUtilsForEditPart.java
index 96b12d008fa..047bd02a9c1 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ServiceUtilsForEditPart.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ServiceUtilsForEditPart.java
@@ -1,56 +1,56 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.gef.EditPart;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-import org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils;
-import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
-import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
-
-/**
- * A helper for manipulating the Papyrus services from an EditPart
- *
- * @author Camille Letavernier
- */
-public class ServiceUtilsForEditPart extends AbstractServiceUtils<EditPart> {
-
- @Override
- public ServicesRegistry getServiceRegistry(EditPart from) throws ServiceException {
- EObject semanticElement = EMFHelper.getEObject(from);
- if (semanticElement == null) {
- Object model = from.getModel();
- if (model instanceof EObject) {
- semanticElement = (EObject) model;
- }
- }
-
- if (semanticElement != null) {
- return ServiceUtilsForEObject.getInstance().getServiceRegistry(semanticElement);
- }
-
- throw new ServiceException("Cannot find the ServicesRegistry from the selected EditPart");
- }
-
- public static ServiceUtilsForEditPart getInstance() {
- return instance;
- }
-
- private static ServiceUtilsForEditPart instance = new ServiceUtilsForEditPart();
-
- private ServiceUtilsForEditPart() {
- // Singleton
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.gef.EditPart;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+import org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils;
+import org.eclipse.papyrus.infra.emf.utils.EMFHelper;
+import org.eclipse.papyrus.infra.emf.utils.ServiceUtilsForEObject;
+
+/**
+ * A helper for manipulating the Papyrus services from an EditPart
+ *
+ * @author Camille Letavernier
+ */
+public class ServiceUtilsForEditPart extends AbstractServiceUtils<EditPart> {
+
+ @Override
+ public ServicesRegistry getServiceRegistry(EditPart from) throws ServiceException {
+ EObject semanticElement = EMFHelper.getEObject(from);
+ if (semanticElement == null) {
+ Object model = from.getModel();
+ if (model instanceof EObject) {
+ semanticElement = (EObject) model;
+ }
+ }
+
+ if (semanticElement != null) {
+ return ServiceUtilsForEObject.getInstance().getServiceRegistry(semanticElement);
+ }
+
+ throw new ServiceException("Cannot find the ServicesRegistry from the selected EditPart");
+ }
+
+ public static ServiceUtilsForEditPart getInstance() {
+ return instance;
+ }
+
+ private static ServiceUtilsForEditPart instance = new ServiceUtilsForEditPart();
+
+ private ServiceUtilsForEditPart() {
+ // Singleton
+ }
+
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConstants.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConstants.java
index 3f436c01e41..cacc83a0667 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConstants.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConstants.java
@@ -1,48 +1,48 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import org.eclipse.papyrus.infra.gmfdiag.common.messages.Messages;
-
-/**
- *
- * This class provides useful constants for Units
- *
- */
-public class UnitsConstants {
-
- private UnitsConstants() {
- // to prevent instanciation
- }
-
- /**
- * 1 inch is equivalent to 2.54 centimeters
- */
- public static final double INCH2CM = 2.54;
-
- /**
- * the string Inches
- */
- public static final String INCHES = Messages.UnitsUtils_Inches;
-
- /**
- * the string millimeters
- */
- public static final String CENTIMETERS = Messages.UnitsUtils_Centimeters;
-
- /**
- * the string pixels
- */
- public static final String PIXELS = Messages.UnitsUtils_Pixels;
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import org.eclipse.papyrus.infra.gmfdiag.common.messages.Messages;
+
+/**
+ *
+ * This class provides useful constants for Units
+ *
+ */
+public class UnitsConstants {
+
+ private UnitsConstants() {
+ // to prevent instanciation
+ }
+
+ /**
+ * 1 inch is equivalent to 2.54 centimeters
+ */
+ public static final double INCH2CM = 2.54;
+
+ /**
+ * the string Inches
+ */
+ public static final String INCHES = Messages.UnitsUtils_Inches;
+
+ /**
+ * the string millimeters
+ */
+ public static final String CENTIMETERS = Messages.UnitsUtils_Centimeters;
+
+ /**
+ * the string pixels
+ */
+ public static final String PIXELS = Messages.UnitsUtils_Pixels;
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConverterUtils.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConverterUtils.java
index 378ce37dc0c..eb073aed8d9 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConverterUtils.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/UnitsConverterUtils.java
@@ -1,108 +1,108 @@
-/*****************************************************************************
- * Copyright (c) 2013 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import java.text.ParseException;
-
-import org.eclipse.gef.rulers.RulerProvider;
-import org.eclipse.swt.widgets.Display;
-
-import com.ibm.icu.text.NumberFormat;
-
-/**
- *
- * This class allows to convert easily units (Centimeters, Pixels and Inches)
- *
- */
-public class UnitsConverterUtils {
-
- private UnitsConverterUtils() {
- // to avoid instanciation
- }
-
- /**
- *
- * @param fromUnits
- * the initial unity
- * @param toUnits
- * the new unity
- * @param valueStr
- * the value to convert
- * @return
- * the new String
- */
- public static final String convertUnits(final int fromUnits, final int toUnits, final String valueStr) {
- // String valueStr = gridSpacing.getStringValue();
- if (fromUnits == toUnits) {
- return valueStr;
- }
-
- // Double value = Double.valueOf( valueStr );
- NumberFormat numberFormatter = NumberFormat.getInstance();
- Double value = new Double(0.125);
- try {
- value = forceDouble(numberFormatter.parse(valueStr));
- } catch (ParseException e) {
- // Use the default
- }
- double pixelValue = 0;
-
- Display display = Display.getDefault();
-
- switch (fromUnits) {
- case RulerProvider.UNIT_INCHES:
- pixelValue = value.doubleValue() * display.getDPI().x;
- break;
- case RulerProvider.UNIT_CENTIMETERS:
- pixelValue = value.doubleValue() * display.getDPI().x / UnitsConstants.INCH2CM;
- break;
- case RulerProvider.UNIT_PIXELS:
- pixelValue = value.intValue();
- break;
- default:
- break;
- }
-
- double returnValue = 0;
- switch (toUnits) {
- case RulerProvider.UNIT_INCHES:
- returnValue = pixelValue / display.getDPI().x;
- break;
- case RulerProvider.UNIT_CENTIMETERS:
- returnValue = pixelValue * UnitsConstants.INCH2CM / display.getDPI().x;
- break;
- case RulerProvider.UNIT_PIXELS:
- returnValue = pixelValue;
- break;
- default:
- break;
- }
-
- return numberFormatter.format(returnValue);
- }
-
- /**
- *
- * @param number
- * a number
- * @return
- * a double
- */
- private static final Double forceDouble(final Number number) {
- if (!(number instanceof Double)) {
- return new Double(number.doubleValue());
- }
- return (Double) number;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2013 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import java.text.ParseException;
+
+import org.eclipse.gef.rulers.RulerProvider;
+import org.eclipse.swt.widgets.Display;
+
+import com.ibm.icu.text.NumberFormat;
+
+/**
+ *
+ * This class allows to convert easily units (Centimeters, Pixels and Inches)
+ *
+ */
+public class UnitsConverterUtils {
+
+ private UnitsConverterUtils() {
+ // to avoid instanciation
+ }
+
+ /**
+ *
+ * @param fromUnits
+ * the initial unity
+ * @param toUnits
+ * the new unity
+ * @param valueStr
+ * the value to convert
+ * @return
+ * the new String
+ */
+ public static final String convertUnits(final int fromUnits, final int toUnits, final String valueStr) {
+ // String valueStr = gridSpacing.getStringValue();
+ if (fromUnits == toUnits) {
+ return valueStr;
+ }
+
+ // Double value = Double.valueOf( valueStr );
+ NumberFormat numberFormatter = NumberFormat.getInstance();
+ Double value = new Double(0.125);
+ try {
+ value = forceDouble(numberFormatter.parse(valueStr));
+ } catch (ParseException e) {
+ // Use the default
+ }
+ double pixelValue = 0;
+
+ Display display = Display.getDefault();
+
+ switch (fromUnits) {
+ case RulerProvider.UNIT_INCHES:
+ pixelValue = value.doubleValue() * display.getDPI().x;
+ break;
+ case RulerProvider.UNIT_CENTIMETERS:
+ pixelValue = value.doubleValue() * display.getDPI().x / UnitsConstants.INCH2CM;
+ break;
+ case RulerProvider.UNIT_PIXELS:
+ pixelValue = value.intValue();
+ break;
+ default:
+ break;
+ }
+
+ double returnValue = 0;
+ switch (toUnits) {
+ case RulerProvider.UNIT_INCHES:
+ returnValue = pixelValue / display.getDPI().x;
+ break;
+ case RulerProvider.UNIT_CENTIMETERS:
+ returnValue = pixelValue * UnitsConstants.INCH2CM / display.getDPI().x;
+ break;
+ case RulerProvider.UNIT_PIXELS:
+ returnValue = pixelValue;
+ break;
+ default:
+ break;
+ }
+
+ return numberFormatter.format(returnValue);
+ }
+
+ /**
+ *
+ * @param number
+ * a number
+ * @return
+ * a double
+ */
+ private static final Double forceDouble(final Number number) {
+ if (!(number instanceof Double)) {
+ return new Double(number.doubleValue());
+ }
+ return (Double) number;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/Util.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/Util.java
index b5b6702f37d..c37e8052768 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/Util.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/Util.java
@@ -1,48 +1,48 @@
-/*****************************************************************************
- * Copyright (c) 2011 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-import org.eclipse.gef.EditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
-import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
-
-
-/**
- * Class that contains utililty methods on top of GMF constructs.
- */
-public class Util {
-
- /**
- * Test if an EditPart is an Affixed Child Node or not
- *
- * @param ep
- * the editpart to test
- * @return <ul>
- * <li> <code>true</code> if the editpart is an Affixed Child Node</li>
- * <li> <code>false</code>if not</li>
- * </ul>
- */
- public static boolean isAffixedChildNode(EditPart ep) {
- if (ep instanceof BorderedBorderItemEditPart) {
- if (ep.getParent() instanceof CompartmentEditPart) {
- return false;
- } else if (ep.getParent() instanceof DiagramEditPart) {
- return false;
- }
- return true;
- }
- return false;
- }
-}
+/*****************************************************************************
+ * Copyright (c) 2011 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+import org.eclipse.gef.EditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.BorderedBorderItemEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.CompartmentEditPart;
+import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
+
+
+/**
+ * Class that contains utililty methods on top of GMF constructs.
+ */
+public class Util {
+
+ /**
+ * Test if an EditPart is an Affixed Child Node or not
+ *
+ * @param ep
+ * the editpart to test
+ * @return <ul>
+ * <li> <code>true</code> if the editpart is an Affixed Child Node</li>
+ * <li> <code>false</code>if not</li>
+ * </ul>
+ */
+ public static boolean isAffixedChildNode(EditPart ep) {
+ if (ep instanceof BorderedBorderItemEditPart) {
+ if (ep.getParent() instanceof CompartmentEditPart) {
+ return false;
+ } else if (ep.getParent() instanceof DiagramEditPart) {
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ViewDescriptorUtil.java b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ViewDescriptorUtil.java
index f5b7761fdd3..1e20107fd49 100644
--- a/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ViewDescriptorUtil.java
+++ b/plugins/infra/gmfdiag/org.eclipse.papyrus.infra.gmfdiag.common/src/org/eclipse/papyrus/infra/gmfdiag/common/utils/ViewDescriptorUtil.java
@@ -1,23 +1,23 @@
-/*****************************************************************************
- * Copyright (c) 2012 CEA LIST.
- *
- * 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:
- *
- * CEA LIST - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.gmfdiag.common.utils;
-
-public class ViewDescriptorUtil {
-
- /** The Constant PERSISTED for use in ViewDescriptor constructors. */
- public static final boolean PERSISTED = true;
-
- /** The Constant PERSISTED_NOT for use in ViewDescriptor constructors. */
- public static final boolean PERSISTED_NOT = false;
-}
+/*****************************************************************************
+ * Copyright (c) 2012 CEA LIST.
+ *
+ * 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:
+ *
+ * CEA LIST - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.gmfdiag.common.utils;
+
+public class ViewDescriptorUtil {
+
+ /** The Constant PERSISTED for use in ViewDescriptor constructors. */
+ public static final boolean PERSISTED = true;
+
+ /** The Constant PERSISTED_NOT for use in ViewDescriptor constructors. */
+ public static final boolean PERSISTED_NOT = false;
+}

Back to the top